From: Axel Lin Date: Tue, 26 Jul 2011 00:13:16 +0000 (-0700) Subject: drivers/leds/leds-sunfire.c: fix sunfire_led_generic_probe() error handling X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=e179840ba88c342d215631356cbfe4e62c9f175b;p=linux-beck.git drivers/leds/leds-sunfire.c: fix sunfire_led_generic_probe() error handling - return -ENOMEM if kzalloc fails, rather than the current -EINVAL - fix a memory leak in the case of goto out_unregister_led_cdevs Signed-off-by: Axel Lin Cc: Richard Purdie Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/leds/leds-sunfire.c b/drivers/leds/leds-sunfire.c index ab6d18f5c39f..1757396b20b3 100644 --- a/drivers/leds/leds-sunfire.c +++ b/drivers/leds/leds-sunfire.c @@ -127,17 +127,19 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, struct led_type *types) { struct sunfire_drvdata *p; - int i, err = -EINVAL; + int i, err; if (pdev->num_resources != 1) { printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n", pdev->num_resources); + err = -EINVAL; goto out; } p = kzalloc(sizeof(*p), GFP_KERNEL); if (!p) { printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n"); + err = -ENOMEM; goto out; } @@ -160,14 +162,14 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, dev_set_drvdata(&pdev->dev, p); - err = 0; -out: - return err; + return 0; out_unregister_led_cdevs: for (i--; i >= 0; i--) led_classdev_unregister(&p->leds[i].led_cdev); - goto out; + kfree(p); +out: + return err; } static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)