leds: convert ADP5520 LED driver to devm_kzalloc() and cleanup error exit path
authorBryan Wu <bryan.wu@canonical.com>
Wed, 4 Jul 2012 04:11:40 +0000 (12:11 +0800)
committerBryan Wu <bryan.wu@canonical.com>
Mon, 23 Jul 2012 23:52:39 +0000 (07:52 +0800)
Cc: Michael Hennerich <hennerich@blackfin.uclinux.org>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
drivers/leds/leds-adp5520.c

index b1400db3f839a2730b6dc29db302306fb3f627eb..aa56a867693afebfcdfc2dd49b739dd37c9029ae 100644 (file)
@@ -119,7 +119,8 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
                return -EFAULT;
        }
 
-       led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
+       led = devm_kzalloc(&pdev->dev, sizeof(*led) * pdata->num_leds,
+                               GFP_KERNEL);
        if (led == NULL) {
                dev_err(&pdev->dev, "failed to alloc memory\n");
                return -ENOMEM;
@@ -129,7 +130,7 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev)
 
        if (ret) {
                dev_err(&pdev->dev, "failed to write\n");
-               goto err_free;
+               return ret;
        }
 
        for (i = 0; i < pdata->num_leds; ++i) {
@@ -179,8 +180,6 @@ err:
                }
        }
 
-err_free:
-       kfree(led);
        return ret;
 }
 
@@ -200,7 +199,6 @@ static int __devexit adp5520_led_remove(struct platform_device *pdev)
                cancel_work_sync(&led[i].work);
        }
 
-       kfree(led);
        return 0;
 }