[PATCH] led: fix memory leak
From: Masakazu Mokuno
Date: Wed Aug 10 2011 - 03:54:53 EST
led: fix memory leak
The memory for struct led_trigger should be properly kfreed in the case of
error of led_trigger_register(). Also this function should return NULL if
error.
Signed-off-by: Masakazu Mokuno <mokuno@xxxxxxxxxxxxx>
---
drivers/leds/led-triggers.c | 5 4 + 1 - 0 !
1 file changed, 4 insertions(+), 1 deletion(-)
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -261,9 +261,12 @@ void led_trigger_register_simple(const c
if (trigger) {
trigger->name = name;
err = led_trigger_register(trigger);
- if (err < 0)
+ if (err < 0) {
+ kfree(trigger);
+ trigger = NULL;
printk(KERN_WARNING "LED trigger %s failed to register"
" (%d)\n", name, err);
+ }
} else
printk(KERN_WARNING "LED trigger %s failed to register"
" (no memory)\n", name);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/