drivers/leds/led-triggers.c: fix memory leak
authorMasakazu Mokuno <Masakazu.Mokuno@jp.sony.com>
Tue, 1 Nov 2011 00:11:59 +0000 (17:11 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 1 Nov 2011 00:30:55 +0000 (17:30 -0700)
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: Masakazu Mokuno <mokuno@sm.sony.co.jp>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/leds/led-triggers.c

index 4bebae733349b90f84230d1b4454942cc9744451..6f1ff93d7cec32862e5cdc7b998586381c401f1c 100644 (file)
@@ -261,9 +261,12 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp)
        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);