diff mbox

[Resend] leds: Use devm_kzalloc in leds-max8997.c file

Message ID 1341372096-25618-1-git-send-email-sachin.kamat@linaro.org
State Accepted
Headers show

Commit Message

Sachin Kamat July 4, 2012, 3:21 a.m. UTC
devm_kzalloc() makes code cleanup simpler.

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

Comments

Bryan Wu July 4, 2012, 4:34 a.m. UTC | #1
On Wed, Jul 4, 2012 at 11:21 AM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
> devm_kzalloc() makes code cleanup simpler.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>

OK, no problem. I applied this to my for-next branch

-Bryan

> ---
>  drivers/leds/leds-max8997.c |   21 ++++++---------------
>  1 files changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
> index f4c0e37..23143be 100644
> --- a/drivers/leds/leds-max8997.c
> +++ b/drivers/leds/leds-max8997.c
> @@ -276,11 +276,9 @@ static int __devinit max8997_led_probe(struct platform_device *pdev)
>                 return -ENODEV;
>         }
>
> -       led = kzalloc(sizeof(*led), GFP_KERNEL);
> -       if (led == NULL) {
> -               ret = -ENOMEM;
> -               goto err_mem;
> -       }
> +       led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
> +       if (led == NULL)
> +               return -ENOMEM;
>
>         led->id = pdev->id;
>         snprintf(name, sizeof(name), "max8997-led%d", pdev->id);
> @@ -315,23 +313,17 @@ static int __devinit max8997_led_probe(struct platform_device *pdev)
>
>         ret = led_classdev_register(&pdev->dev, &led->cdev);
>         if (ret < 0)
> -               goto err_led;
> +               return ret;
>
>         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_led:
> -       kfree(led);
> -err_mem:
> -       return ret;
>  }
>
>  static int __devexit max8997_led_remove(struct platform_device *pdev)
> @@ -340,7 +332,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..23143be 100644
--- a/drivers/leds/leds-max8997.c
+++ b/drivers/leds/leds-max8997.c
@@ -276,11 +276,9 @@  static int __devinit max8997_led_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	led = kzalloc(sizeof(*led), GFP_KERNEL);
-	if (led == NULL) {
-		ret = -ENOMEM;
-		goto err_mem;
-	}
+	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
+	if (led == NULL)
+		return -ENOMEM;
 
 	led->id = pdev->id;
 	snprintf(name, sizeof(name), "max8997-led%d", pdev->id);
@@ -315,23 +313,17 @@  static int __devinit max8997_led_probe(struct platform_device *pdev)
 
 	ret = led_classdev_register(&pdev->dev, &led->cdev);
 	if (ret < 0)
-		goto err_led;
+		return ret;
 
 	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_led:
-	kfree(led);
-err_mem:
-	return ret;
 }
 
 static int __devexit max8997_led_remove(struct platform_device *pdev)
@@ -340,7 +332,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;
 }