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 <axel.lin@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Axel Lin 2011-07-25 17:13:16 -07:00 committed by Linus Torvalds
parent 19ab5cb8fb
commit e179840ba8

View file

@ -127,17 +127,19 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
struct led_type *types) struct led_type *types)
{ {
struct sunfire_drvdata *p; struct sunfire_drvdata *p;
int i, err = -EINVAL; int i, err;
if (pdev->num_resources != 1) { if (pdev->num_resources != 1) {
printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n", printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n",
pdev->num_resources); pdev->num_resources);
err = -EINVAL;
goto out; goto out;
} }
p = kzalloc(sizeof(*p), GFP_KERNEL); p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n"); printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n");
err = -ENOMEM;
goto out; goto out;
} }
@ -160,14 +162,14 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
dev_set_drvdata(&pdev->dev, p); dev_set_drvdata(&pdev->dev, p);
err = 0; return 0;
out:
return err;
out_unregister_led_cdevs: out_unregister_led_cdevs:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
led_classdev_unregister(&p->leds[i].led_cdev); 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) static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)