diff mbox

[3/5] leds: Use devm_kzalloc in leds-gpio.c file

Message ID 1341316074-14886-3-git-send-email-sachin.kamat@linaro.org
State Superseded
Headers show

Commit Message

Sachin Kamat July 3, 2012, 11:47 a.m. UTC
devm_kzalloc() makes cleanup simpler.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/leds/leds-gpio.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

Comments

Bryan Wu July 4, 2012, 3:02 a.m. UTC | #1
On Tue, Jul 3, 2012 at 7:47 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> devm_kzalloc() makes cleanup simpler.
>

This looks good, but I think you missed another kzalloc() call when
using device tree.

Please update that kzalloc() as well and Cc the author of this driver.

-Bryan

> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/leds/leds-gpio.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
> index f4c470a..23b49a4 100644
> --- a/drivers/leds/leds-gpio.c
> +++ b/drivers/leds/leds-gpio.c
> @@ -239,8 +239,9 @@ static int __devinit gpio_led_probe(struct platform_device *pdev)
>         int i, ret = 0;
>
>         if (pdata && pdata->num_leds) {
> -               priv = kzalloc(sizeof_gpio_leds_priv(pdata->num_leds),
> -                               GFP_KERNEL);
> +               priv = devm_kzalloc(&pdev->dev,
> +                               sizeof_gpio_leds_priv(pdata->num_leds),
> +                                       GFP_KERNEL);
>                 if (!priv)
>                         return -ENOMEM;
>
> @@ -253,7 +254,6 @@ static int __devinit gpio_led_probe(struct platform_device *pdev)
>                                 /* On failure: unwind the led creations */
>                                 for (i = i - 1; i >= 0; i--)
>                                         delete_gpio_led(&priv->leds[i]);
> -                               kfree(priv);
>                                 return ret;
>                         }
>                 }
> @@ -277,7 +277,6 @@ static int __devexit gpio_led_remove(struct platform_device *pdev)
>                 delete_gpio_led(&priv->leds[i]);
>
>         dev_set_drvdata(&pdev->dev, NULL);
> -       kfree(priv);
>
>         return 0;
>  }
> --
> 1.7.4.1
>
Sachin Kamat July 4, 2012, 3:44 a.m. UTC | #2
On 04/07/2012, Bryan Wu <bryan.wu@canonical.com> wrote:
> On Tue, Jul 3, 2012 at 7:47 PM, Sachin Kamat <sachin.kamat@linaro.org>
> wrote:
>> devm_kzalloc() makes cleanup simpler.
>>
>
> This looks good, but I think you missed another kzalloc() call when
> using device tree.
>
> Please update that kzalloc() as well and Cc the author of this driver.

Ok. I will update and resend the patch.

>
> -Bryan
>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> ---
>>  drivers/leds/leds-gpio.c |    7 +++----
>>  1 files changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
>> index f4c470a..23b49a4 100644
>> --- a/drivers/leds/leds-gpio.c
>> +++ b/drivers/leds/leds-gpio.c
>> @@ -239,8 +239,9 @@ static int __devinit gpio_led_probe(struct
>> platform_device *pdev)
>>         int i, ret = 0;
>>
>>         if (pdata && pdata->num_leds) {
>> -               priv = kzalloc(sizeof_gpio_leds_priv(pdata->num_leds),
>> -                               GFP_KERNEL);
>> +               priv = devm_kzalloc(&pdev->dev,
>> +                               sizeof_gpio_leds_priv(pdata->num_leds),
>> +                                       GFP_KERNEL);
>>                 if (!priv)
>>                         return -ENOMEM;
>>
>> @@ -253,7 +254,6 @@ static int __devinit gpio_led_probe(struct
>> platform_device *pdev)
>>                                 /* On failure: unwind the led creations
>> */
>>                                 for (i = i - 1; i >= 0; i--)
>>                                         delete_gpio_led(&priv->leds[i]);
>> -                               kfree(priv);
>>                                 return ret;
>>                         }
>>                 }
>> @@ -277,7 +277,6 @@ static int __devexit gpio_led_remove(struct
>> platform_device *pdev)
>>                 delete_gpio_led(&priv->leds[i]);
>>
>>         dev_set_drvdata(&pdev->dev, NULL);
>> -       kfree(priv);
>>
>>         return 0;
>>  }
>> --
>> 1.7.4.1
>>
>
>
>
> --
> Bryan Wu <bryan.wu@canonical.com>
> Kernel Developer    +86.186-168-78255 Mobile
> Canonical Ltd.      www.canonical.com
> Ubuntu - Linux for human beings | www.ubuntu.com
>
diff mbox

Patch

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index f4c470a..23b49a4 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -239,8 +239,9 @@  static int __devinit gpio_led_probe(struct platform_device *pdev)
 	int i, ret = 0;
 
 	if (pdata && pdata->num_leds) {
-		priv = kzalloc(sizeof_gpio_leds_priv(pdata->num_leds),
-				GFP_KERNEL);
+		priv = devm_kzalloc(&pdev->dev,
+				sizeof_gpio_leds_priv(pdata->num_leds),
+					GFP_KERNEL);
 		if (!priv)
 			return -ENOMEM;
 
@@ -253,7 +254,6 @@  static int __devinit gpio_led_probe(struct platform_device *pdev)
 				/* On failure: unwind the led creations */
 				for (i = i - 1; i >= 0; i--)
 					delete_gpio_led(&priv->leds[i]);
-				kfree(priv);
 				return ret;
 			}
 		}
@@ -277,7 +277,6 @@  static int __devexit gpio_led_remove(struct platform_device *pdev)
 		delete_gpio_led(&priv->leds[i]);
 
 	dev_set_drvdata(&pdev->dev, NULL);
-	kfree(priv);
 
 	return 0;
 }