All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds-88pm860x: use devm_kzalloc function
@ 2012-07-02 10:15 Devendra Naga
  2012-07-02 13:51 ` Bryan Wu
  0 siblings, 1 reply; 2+ messages in thread
From: Devendra Naga @ 2012-07-02 10:15 UTC (permalink / raw)
  To: Bryan Wu, Richard Purdie, linux-leds, linux-kernel; +Cc: Devendra Naga

Using devm_kzalloc will remove all the error checks and the frees are automatically done at the driver unload side.

Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
---

Thanks Bryan for advising me.. ;-)

 drivers/leds/leds-88pm860x.c |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 5b61aaf..61897cf 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -209,7 +209,7 @@ static int pm860x_led_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
+	data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL);
 	if (data == NULL)
 		return -ENOMEM;
 	strncpy(data->name, res->name, MFD_NAME_SIZE - 1);
@@ -220,7 +220,6 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	data->port = pdata->flags;
 	if (data->port < 0) {
 		dev_err(&pdev->dev, "check device failed\n");
-		kfree(data);
 		return -EINVAL;
 	}
 
@@ -233,13 +232,10 @@ static int pm860x_led_probe(struct platform_device *pdev)
 	ret = led_classdev_register(chip->dev, &data->cdev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
-		goto out;
+		return ret;
 	}
 	pm860x_led_set(&data->cdev, 0);
 	return 0;
-out:
-	kfree(data);
-	return ret;
 }
 
 static int pm860x_led_remove(struct platform_device *pdev)
@@ -247,7 +243,6 @@ static int pm860x_led_remove(struct platform_device *pdev)
 	struct pm860x_led *data = platform_get_drvdata(pdev);
 
 	led_classdev_unregister(&data->cdev);
-	kfree(data);
 
 	return 0;
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] leds-88pm860x: use devm_kzalloc function
  2012-07-02 10:15 [PATCH] leds-88pm860x: use devm_kzalloc function Devendra Naga
@ 2012-07-02 13:51 ` Bryan Wu
  0 siblings, 0 replies; 2+ messages in thread
From: Bryan Wu @ 2012-07-02 13:51 UTC (permalink / raw)
  To: Devendra Naga; +Cc: Richard Purdie, linux-leds, linux-kernel

On Mon, Jul 2, 2012 at 6:15 PM, Devendra Naga <devendra.aaru@gmail.com> wrote:
> Using devm_kzalloc will remove all the error checks and the frees are automatically done at the driver unload side.
>
> Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>

Great, Applied to my for-next branch. Thanks,

-Bryan

> ---
>
> Thanks Bryan for advising me.. ;-)
>
>  drivers/leds/leds-88pm860x.c |    9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
> index 5b61aaf..61897cf 100644
> --- a/drivers/leds/leds-88pm860x.c
> +++ b/drivers/leds/leds-88pm860x.c
> @@ -209,7 +209,7 @@ static int pm860x_led_probe(struct platform_device *pdev)
>                 return -EINVAL;
>         }
>
> -       data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
> +       data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL);
>         if (data == NULL)
>                 return -ENOMEM;
>         strncpy(data->name, res->name, MFD_NAME_SIZE - 1);
> @@ -220,7 +220,6 @@ static int pm860x_led_probe(struct platform_device *pdev)
>         data->port = pdata->flags;
>         if (data->port < 0) {
>                 dev_err(&pdev->dev, "check device failed\n");
> -               kfree(data);
>                 return -EINVAL;
>         }
>
> @@ -233,13 +232,10 @@ static int pm860x_led_probe(struct platform_device *pdev)
>         ret = led_classdev_register(chip->dev, &data->cdev);
>         if (ret < 0) {
>                 dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
> -               goto out;
> +               return ret;
>         }
>         pm860x_led_set(&data->cdev, 0);
>         return 0;
> -out:
> -       kfree(data);
> -       return ret;
>  }
>
>  static int pm860x_led_remove(struct platform_device *pdev)
> @@ -247,7 +243,6 @@ static int pm860x_led_remove(struct platform_device *pdev)
>         struct pm860x_led *data = platform_get_drvdata(pdev);
>
>         led_classdev_unregister(&data->cdev);
> -       kfree(data);
>
>         return 0;
>  }
> --
> 1.7.9.5
>



-- 
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-02 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-02 10:15 [PATCH] leds-88pm860x: use devm_kzalloc function Devendra Naga
2012-07-02 13:51 ` Bryan Wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.