提交 cba4c2ac 编写于 作者: M Masakazu Mokuno 提交者: Linus Torvalds

drivers/leds/led-triggers.c: fix memory leak

The memory for struct led_trigger should be kfreed in the
led_trigger_register() error path.  Also this function should return NULL
on error.
Signed-off-by: NMasakazu Mokuno <mokuno@sm.sony.co.jp>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 f59b6f9f
...@@ -261,9 +261,12 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp) ...@@ -261,9 +261,12 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp)
if (trigger) { if (trigger) {
trigger->name = name; trigger->name = name;
err = led_trigger_register(trigger); err = led_trigger_register(trigger);
if (err < 0) if (err < 0) {
kfree(trigger);
trigger = NULL;
printk(KERN_WARNING "LED trigger %s failed to register" printk(KERN_WARNING "LED trigger %s failed to register"
" (%d)\n", name, err); " (%d)\n", name, err);
}
} else } else
printk(KERN_WARNING "LED trigger %s failed to register" printk(KERN_WARNING "LED trigger %s failed to register"
" (no memory)\n", name); " (no memory)\n", name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册