diff mbox series

pwm: omap-dmtimer: Add missing put_device() call in pwm_omap_dmtimer_probe()

Message ID fd7a56e4-2a35-a6c4-e5bd-1e53a6c48687@web.de
State Changes Requested
Headers show
Series pwm: omap-dmtimer: Add missing put_device() call in pwm_omap_dmtimer_probe() | expand

Commit Message

Markus Elfring Nov. 9, 2019, 12:26 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 13:09:42 +0100

A coccicheck run provided information like the following.

drivers/pwm/pwm-omap-dmtimer.c:304:2-8: ERROR: missing put_device;
call of_find_device_by_node on line 255, but without a corresponding
object release within this function.

Generated by: scripts/coccinelle/free/put_device.cocci

Thus add jump targets to fix the exception handling for this
function implementation.

Fixes: b7290cf6ff7869ec12070aa146c370728cab62c2 ("pwm: pwm-omap-dmtimer: Adapt driver to utilize dmtimer pdata ops")
Fixes: 6604c6556db9e41c85f2839f66bd9d617bcf9f87 ("pwm: Add PWM driver for OMAP using dual-mode timers")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/pwm/pwm-omap-dmtimer.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

--
2.24.0

Comments

Uwe Kleine-König Nov. 11, 2019, 7:19 a.m. UTC | #1
Hello Markus,

On Sat, Nov 09, 2019 at 01:26:50PM +0100, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 9 Nov 2019 13:09:42 +0100
> 
> A coccicheck run provided information like the following.
> 
> drivers/pwm/pwm-omap-dmtimer.c:304:2-8: ERROR: missing put_device;
> call of_find_device_by_node on line 255, but without a corresponding
> object release within this function.
> 
> Generated by: scripts/coccinelle/free/put_device.cocci
> 
> Thus add jump targets to fix the exception handling for this
> function implementation.
> 
> Fixes: b7290cf6ff7869ec12070aa146c370728cab62c2 ("pwm: pwm-omap-dmtimer: Adapt driver to utilize dmtimer pdata ops")
> Fixes: 6604c6556db9e41c85f2839f66bd9d617bcf9f87 ("pwm: Add PWM driver for OMAP using dual-mode timers")
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/pwm/pwm-omap-dmtimer.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c
> index 00772fc53490..958854213786 100644
> --- a/drivers/pwm/pwm-omap-dmtimer.c
> +++ b/drivers/pwm/pwm-omap-dmtimer.c
> @@ -301,12 +301,13 @@ static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
>  put:
>  	of_node_put(timer);
>  	if (ret < 0)
> -		return ret;
> +		goto check_timer_pdev;
> 
>  	omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL);
>  	if (!omap) {
>  		pdata->free(dm_timer);
> -		return -ENOMEM;
> +		ret = -ENOMEM;
> +		goto put_device;
>  	}
> 
>  	omap->pdata = pdata;
> @@ -340,12 +341,19 @@ static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "failed to register PWM\n");
>  		omap->pdata->free(omap->dm_timer);
> -		return ret;
> +		goto put_device;
>  	}
> 
>  	platform_set_drvdata(pdev, omap);
> 
>  	return 0;
> +
> +check_timer_pdev:
> +	if (timer_pdev)
> +put_device:
> +		put_device(&timer_pdev->dev);

This is ugly but necessary with the driver as is because the error
handling is interwinded within the normal path through this function.

I would prefer to clean this up first, then this fix gets a bit nicer.
Will send a patch in reply to this mail.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c
index 00772fc53490..958854213786 100644
--- a/drivers/pwm/pwm-omap-dmtimer.c
+++ b/drivers/pwm/pwm-omap-dmtimer.c
@@ -301,12 +301,13 @@  static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
 put:
 	of_node_put(timer);
 	if (ret < 0)
-		return ret;
+		goto check_timer_pdev;

 	omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL);
 	if (!omap) {
 		pdata->free(dm_timer);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto put_device;
 	}

 	omap->pdata = pdata;
@@ -340,12 +341,19 @@  static int pwm_omap_dmtimer_probe(struct platform_device *pdev)
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to register PWM\n");
 		omap->pdata->free(omap->dm_timer);
-		return ret;
+		goto put_device;
 	}

 	platform_set_drvdata(pdev, omap);

 	return 0;
+
+check_timer_pdev:
+	if (timer_pdev)
+put_device:
+		put_device(&timer_pdev->dev);
+
+	return ret;
 }

 static int pwm_omap_dmtimer_remove(struct platform_device *pdev)