Patchwork [2/2] rtc: Convert wm831x driver to devm_kzalloc()

login
register
mail settings
Submitter Mark Brown
Date Dec. 3, 2011, 9:28 p.m.
Message ID <1322947689-26393-2-git-send-email-broonie@opensource.wolfsonmicro.com>
Download mbox | patch
Permalink /patch/129115/
State New
Headers show

Comments

Mark Brown - Dec. 3, 2011, 9:28 p.m.
Marginally less code and eliminate the possibility of memory leaks.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/rtc/rtc-wm831x.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
Jean-Christophe PLAGNIOL-VILLARD - Dec. 4, 2011, 8:04 a.m.
Ack


Best Regards,
J.



On 21:28 Sat 03 Dec     , Mark Brown wrote:

> Marginally less code and eliminate the possibility of memory leaks.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  drivers/rtc/rtc-wm831x.c |    4 +---
>  1 files changed, 1 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
> index dabbd45..657c6f6 100644
> --- a/drivers/rtc/rtc-wm831x.c
> +++ b/drivers/rtc/rtc-wm831x.c
> @@ -399,7 +399,7 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
>  	int alm_irq = platform_get_irq_byname(pdev, "ALM");
>  	int ret = 0;
>  
> -	wm831x_rtc = kzalloc(sizeof(*wm831x_rtc), GFP_KERNEL);
> +	wm831x_rtc = devm_kzalloc(&pdev->dev, sizeof(*wm831x_rtc), GFP_KERNEL);
>  	if (wm831x_rtc == NULL)
>  		return -ENOMEM;
>  
> @@ -434,7 +434,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err:
> -	kfree(wm831x_rtc);
>  	return ret;
>  }
>  
> @@ -445,7 +444,6 @@ static int __devexit wm831x_rtc_remove(struct platform_device *pdev)
>  
>  	free_irq(alm_irq, wm831x_rtc);
>  	rtc_device_unregister(wm831x_rtc->rtc);
> -	kfree(wm831x_rtc);
>  
>  	return 0;
>  }
> -- 
> 1.7.7.3
> 
> -- 
> You received this message because you are subscribed to "rtc-linux".
> Membership options at http://groups.google.com/group/rtc-linux .
> Please read http://groups.google.com/group/rtc-linux/web/checklist
> before submitting a driver.

Patch

diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index dabbd45..657c6f6 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -399,7 +399,7 @@  static int wm831x_rtc_probe(struct platform_device *pdev)
 	int alm_irq = platform_get_irq_byname(pdev, "ALM");
 	int ret = 0;
 
-	wm831x_rtc = kzalloc(sizeof(*wm831x_rtc), GFP_KERNEL);
+	wm831x_rtc = devm_kzalloc(&pdev->dev, sizeof(*wm831x_rtc), GFP_KERNEL);
 	if (wm831x_rtc == NULL)
 		return -ENOMEM;
 
@@ -434,7 +434,6 @@  static int wm831x_rtc_probe(struct platform_device *pdev)
 	return 0;
 
 err:
-	kfree(wm831x_rtc);
 	return ret;
 }
 
@@ -445,7 +444,6 @@  static int __devexit wm831x_rtc_remove(struct platform_device *pdev)
 
 	free_irq(alm_irq, wm831x_rtc);
 	rtc_device_unregister(wm831x_rtc->rtc);
-	kfree(wm831x_rtc);
 
 	return 0;
 }