aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/timer.c
diff options
context:
space:
mode:
authorQi Hou <qi.hou@windriver.com>2018-01-10 23:54:43 -0500
committerTony Lindgren <tony@atomide.com>2018-02-14 11:29:45 -0500
commitdb35340c536f1af0108ec9a0b2126a05d358d14a (patch)
tree694824bc296cf6f1a8ee3fe419a63cdde30204ee /arch/arm/mach-omap2/timer.c
parent60c99c7749f2a86e8891b003496fa8f6e985b8b5 (diff)
ARM: OMAP2+: timer: fix a kmemleak caused in omap_get_timer_dt
When more than one GP timers are used as kernel system timers and the corresponding nodes in device-tree are marked with the same "disabled" property, then the "attr" field of the property will be initialized more than once as the property being added to sys file system via __of_add_property_sysfs(). In __of_add_property_sysfs(), the "name" field of pp->attr.attr is set directly to the return value of safe_name(), without taking care of whether it's already a valid pointer to a memory block. If it is, its old value will always be overwritten by the new one and the memory block allocated before will a "ghost", then a kmemleak happened. That the same "disabled" property being added to different nodes of device tree would cause that kind of kmemleak overhead, at least once. To fix it, allocate the property dynamically, and delete static one. Signed-off-by: Qi Hou <qi.hou@windriver.com> Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch/arm/mach-omap2/timer.c')
-rw-r--r--arch/arm/mach-omap2/timer.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c
index ece09c9461f7..d61fbd7a2840 100644
--- a/arch/arm/mach-omap2/timer.c
+++ b/arch/arm/mach-omap2/timer.c
@@ -156,12 +156,6 @@ static struct clock_event_device clockevent_gpt = {
156 .tick_resume = omap2_gp_timer_shutdown, 156 .tick_resume = omap2_gp_timer_shutdown,
157}; 157};
158 158
159static struct property device_disabled = {
160 .name = "status",
161 .length = sizeof("disabled"),
162 .value = "disabled",
163};
164
165static const struct of_device_id omap_timer_match[] __initconst = { 159static const struct of_device_id omap_timer_match[] __initconst = {
166 { .compatible = "ti,omap2420-timer", }, 160 { .compatible = "ti,omap2420-timer", },
167 { .compatible = "ti,omap3430-timer", }, 161 { .compatible = "ti,omap3430-timer", },
@@ -203,8 +197,17 @@ static struct device_node * __init omap_get_timer_dt(const struct of_device_id *
203 of_get_property(np, "ti,timer-secure", NULL))) 197 of_get_property(np, "ti,timer-secure", NULL)))
204 continue; 198 continue;
205 199
206 if (!of_device_is_compatible(np, "ti,omap-counter32k")) 200 if (!of_device_is_compatible(np, "ti,omap-counter32k")) {
207 of_add_property(np, &device_disabled); 201 struct property *prop;
202
203 prop = kzalloc(sizeof(*prop), GFP_KERNEL);
204 if (!prop)
205 return NULL;
206 prop->name = "status";
207 prop->value = "disabled";
208 prop->length = strlen(prop->value);
209 of_add_property(np, prop);
210 }
208 return np; 211 return np;
209 } 212 }
210 213