Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Qi Hou and committed by
Tony Lindgren
db35340c 60c99c77

+11 -8
+11 -8
arch/arm/mach-omap2/timer.c
··· 156 156 .tick_resume = omap2_gp_timer_shutdown, 157 157 }; 158 158 159 - static struct property device_disabled = { 160 - .name = "status", 161 - .length = sizeof("disabled"), 162 - .value = "disabled", 163 - }; 164 - 165 159 static const struct of_device_id omap_timer_match[] __initconst = { 166 160 { .compatible = "ti,omap2420-timer", }, 167 161 { .compatible = "ti,omap3430-timer", }, ··· 197 203 of_get_property(np, "ti,timer-secure", NULL))) 198 204 continue; 199 205 200 - if (!of_device_is_compatible(np, "ti,omap-counter32k")) 201 - of_add_property(np, &device_disabled); 206 + if (!of_device_is_compatible(np, "ti,omap-counter32k")) { 207 + struct property *prop; 208 + 209 + prop = kzalloc(sizeof(*prop), GFP_KERNEL); 210 + if (!prop) 211 + return NULL; 212 + prop->name = "status"; 213 + prop->value = "disabled"; 214 + prop->length = strlen(prop->value); 215 + of_add_property(np, prop); 216 + } 202 217 return np; 203 218 } 204 219