diff mbox

[1/5] leds: Use devm_kzalloc in leds-max8997.c file

Message ID 1341316074-14886-1-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 code cleanup simpler.

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

Comments

Bryan Wu July 4, 2012, 2:58 a.m. UTC | #1
On Tue, Jul 3, 2012 at 7:47 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> devm_kzalloc() makes code cleanup simpler.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/leds/leds-max8997.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
> index f4c0e37..d9bcb49 100644
> --- a/drivers/leds/leds-max8997.c
> +++ b/drivers/leds/leds-max8997.c
> @@ -276,7 +276,7 @@ static int __devinit max8997_led_probe(struct platform_device *pdev)
>                 return -ENODEV;
>         }
>
> -       led = kzalloc(sizeof(*led), GFP_KERNEL);
> +       led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
>         if (led == NULL) {
>                 ret = -ENOMEM;
>                 goto err_mem;

we can just return -ENOMEM;

> @@ -315,7 +315,7 @@ static int __devinit max8997_led_probe(struct platform_device *pdev)
>
>         ret = led_classdev_register(&pdev->dev, &led->cdev);
>         if (ret < 0)
> -               goto err_led;
> +               goto err_mem;
just "return ret;"

>
>         ret = device_create_file(led->cdev.dev, &dev_attr_mode);
>         if (ret != 0) {
> @@ -328,8 +328,6 @@ static int __devinit max8997_led_probe(struct platform_device *pdev)
>
>  err_file:
>         led_classdev_unregister(&led->cdev);
> -err_led:
> -       kfree(led);
>  err_mem:
>         return ret;

we can totally remove this error handling like this:
--
        ret = device_create_file(led->cdev.dev, &dev_attr_mode);
        if (ret != 0) {
                dev_err(&pdev->dev,
                        "failed to create file: %d\n", ret);
-               goto err_file;
+               led_classdev_unregister(&led->cdev);
+               return ret;
        }

        return 0;
-
-err_file:
-       led_classdev_unregister(&led->cdev);
-err_mem:
-       return ret;
--

Could you please update your patch? and please Cc the author of this driver.

Thanks,
-Bryan

>  }
> @@ -340,7 +338,6 @@ static int __devexit max8997_led_remove(struct platform_device *pdev)
>
>         device_remove_file(led->cdev.dev, &dev_attr_mode);
>         led_classdev_unregister(&led->cdev);
> -       kfree(led);
>
>         return 0;
>  }
> --
> 1.7.4.1
>
Sachin Kamat July 4, 2012, 3:30 a.m. UTC | #2
Thanks for the review.


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 code cleanup simpler.
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> ---
>>  drivers/leds/leds-max8997.c |    7 ++-----
>>  1 files changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
>> index f4c0e37..d9bcb49 100644
>> --- a/drivers/leds/leds-max8997.c
>> +++ b/drivers/leds/leds-max8997.c
>> @@ -276,7 +276,7 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>                 return -ENODEV;
>>         }
>>
>> -       led = kzalloc(sizeof(*led), GFP_KERNEL);
>> +       led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
>>         if (led == NULL) {
>>                 ret = -ENOMEM;
>>                 goto err_mem;
>
> we can just return -ENOMEM;
>
>> @@ -315,7 +315,7 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>
>>         ret = led_classdev_register(&pdev->dev, &led->cdev);
>>         if (ret < 0)
>> -               goto err_led;
>> +               goto err_mem;
> just "return ret;"
>
>>
>>         ret = device_create_file(led->cdev.dev, &dev_attr_mode);
>>         if (ret != 0) {
>> @@ -328,8 +328,6 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>
>>  err_file:
>>         led_classdev_unregister(&led->cdev);
>> -err_led:
>> -       kfree(led);
>>  err_mem:
>>         return ret;
>
> we can totally remove this error handling like this:
> --
>         ret = device_create_file(led->cdev.dev, &dev_attr_mode);
>         if (ret != 0) {
>                 dev_err(&pdev->dev,
>                         "failed to create file: %d\n", ret);
> -               goto err_file;
> +               led_classdev_unregister(&led->cdev);
> +               return ret;
>         }
>
>         return 0;
> -
> -err_file:
> -       led_classdev_unregister(&led->cdev);
> -err_mem:
> -       return ret;
> --
>
> Could you please update your patch?

Somehow I happened to overlook these cases. I will update the same.

and please Cc the author of this
> driver.
>
Sure. Updated patch is on its way.

> Thanks,
> -Bryan
>
>>  }
>> @@ -340,7 +338,6 @@ static int __devexit max8997_led_remove(struct
>> platform_device *pdev)
>>
>>         device_remove_file(led->cdev.dev, &dev_attr_mode);
>>         led_classdev_unregister(&led->cdev);
>> -       kfree(led);
>>
>>         return 0;
>>  }
>> --
>> 1.7.4.1
>>
>
Sachin Kamat July 4, 2012, 3:38 a.m. UTC | #3
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 code cleanup simpler.
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> ---
>>  drivers/leds/leds-max8997.c |    7 ++-----
>>  1 files changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
>> index f4c0e37..d9bcb49 100644
>> --- a/drivers/leds/leds-max8997.c
>> +++ b/drivers/leds/leds-max8997.c
>> @@ -276,7 +276,7 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>                 return -ENODEV;
>>         }
>>
>> -       led = kzalloc(sizeof(*led), GFP_KERNEL);
>> +       led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
>>         if (led == NULL) {
>>                 ret = -ENOMEM;
>>                 goto err_mem;
>
> we can just return -ENOMEM;
>
>> @@ -315,7 +315,7 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>
>>         ret = led_classdev_register(&pdev->dev, &led->cdev);
>>         if (ret < 0)
>> -               goto err_led;
>> +               goto err_mem;
> just "return ret;"
>
>>
>>         ret = device_create_file(led->cdev.dev, &dev_attr_mode);
>>         if (ret != 0) {
>> @@ -328,8 +328,6 @@ static int __devinit max8997_led_probe(struct
>> platform_device *pdev)
>>
>>  err_file:
>>         led_classdev_unregister(&led->cdev);
>> -err_led:
>> -       kfree(led);
>>  err_mem:
>>         return ret;
>
> we can totally remove this error handling like this:
> --
>         ret = device_create_file(led->cdev.dev, &dev_attr_mode);
>         if (ret != 0) {
>                 dev_err(&pdev->dev,
>                         "failed to create file: %d\n", ret);
> -               goto err_file;
> +               led_classdev_unregister(&led->cdev);
> +               return ret;
>         }
>
>         return 0;
> -
> -err_file:
> -       led_classdev_unregister(&led->cdev);
> -err_mem:
> -       return ret;
> --
>
> Could you please update your patch? and please Cc the author of this
> driver.

The author's e-mail address (dg77.kim@samsung.com) seems to have
changed. I received a mail delivery failure notification.


>
> Thanks,
> -Bryan
>
>>  }
>> @@ -340,7 +338,6 @@ static int __devexit max8997_led_remove(struct
>> platform_device *pdev)
>>
>>         device_remove_file(led->cdev.dev, &dev_attr_mode);
>>         led_classdev_unregister(&led->cdev);
>> -       kfree(led);
>>
>>         return 0;
>>  }
>> --
>> 1.7.4.1
>>
>
diff mbox

Patch

diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
index f4c0e37..d9bcb49 100644
--- a/drivers/leds/leds-max8997.c
+++ b/drivers/leds/leds-max8997.c
@@ -276,7 +276,7 @@  static int __devinit max8997_led_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	led = kzalloc(sizeof(*led), GFP_KERNEL);
+	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
 	if (led == NULL) {
 		ret = -ENOMEM;
 		goto err_mem;
@@ -315,7 +315,7 @@  static int __devinit max8997_led_probe(struct platform_device *pdev)
 
 	ret = led_classdev_register(&pdev->dev, &led->cdev);
 	if (ret < 0)
-		goto err_led;
+		goto err_mem;
 
 	ret = device_create_file(led->cdev.dev, &dev_attr_mode);
 	if (ret != 0) {
@@ -328,8 +328,6 @@  static int __devinit max8997_led_probe(struct platform_device *pdev)
 
 err_file:
 	led_classdev_unregister(&led->cdev);
-err_led:
-	kfree(led);
 err_mem:
 	return ret;
 }
@@ -340,7 +338,6 @@  static int __devexit max8997_led_remove(struct platform_device *pdev)
 
 	device_remove_file(led->cdev.dev, &dev_attr_mode);
 	led_classdev_unregister(&led->cdev);
-	kfree(led);
 
 	return 0;
 }