Commit 234699a8 authored by Bryan Wu's avatar Bryan Wu

leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path

Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBryan Wu <bryan.wu@canonical.com>
parent 0f4630c9
...@@ -132,15 +132,13 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, ...@@ -132,15 +132,13 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
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; return -EINVAL;
goto out;
} }
p = kzalloc(sizeof(*p), GFP_KERNEL); p = devm_kzalloc(&pdev->dev, 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; return -ENOMEM;
goto out;
} }
for (i = 0; i < NUM_LEDS_PER_BOARD; i++) { for (i = 0; i < NUM_LEDS_PER_BOARD; i++) {
...@@ -156,20 +154,15 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, ...@@ -156,20 +154,15 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev,
if (err) { if (err) {
printk(KERN_ERR PFX "Could not register %s LED\n", printk(KERN_ERR PFX "Could not register %s LED\n",
lp->name); lp->name);
goto out_unregister_led_cdevs; for (i--; i >= 0; i--)
led_classdev_unregister(&p->leds[i].led_cdev);
return err;
} }
} }
dev_set_drvdata(&pdev->dev, p); dev_set_drvdata(&pdev->dev, p);
return 0; return 0;
out_unregister_led_cdevs:
for (i--; i >= 0; i--)
led_classdev_unregister(&p->leds[i].led_cdev);
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)
...@@ -180,8 +173,6 @@ static int __devexit sunfire_led_generic_remove(struct platform_device *pdev) ...@@ -180,8 +173,6 @@ static int __devexit sunfire_led_generic_remove(struct platform_device *pdev)
for (i = 0; i < NUM_LEDS_PER_BOARD; i++) for (i = 0; i < NUM_LEDS_PER_BOARD; i++)
led_classdev_unregister(&p->leds[i].led_cdev); led_classdev_unregister(&p->leds[i].led_cdev);
kfree(p);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment