linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: sti: Fix the error handling path of sti_pwm_probe()
@ 2023-04-16  8:32 Christophe JAILLET
  2023-04-16 17:02 ` Uwe Kleine-König
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-04-16  8:32 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König, Lee Jones
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-pwm

Rewrite the error handing path of sti_pwm_probe() to avoid some leaks.

Fixes: 3f0925b5a864 ("pwm: sti: Initialise PWM capture device data")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I also wonder if some clk_put() are also missing in the error handling path
and in the remove function.

This could be split in several patches because some issues were
introduced before 3f0925b5a864.
But it is already nearly 7 years old, so it should be enough, should it be
back-ported.
---
 drivers/pwm/pwm-sti.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
index b1d1373648a3..7e678cab2991 100644
--- a/drivers/pwm/pwm-sti.c
+++ b/drivers/pwm/pwm-sti.c
@@ -630,13 +630,14 @@ static int sti_pwm_probe(struct platform_device *pdev)
 		pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
 		if (IS_ERR(pc->cpt_clk)) {
 			dev_err(dev, "failed to get PWM capture clock\n");
-			return PTR_ERR(pc->cpt_clk);
+			ret = PTR_ERR(pc->cpt_clk);
+			goto err_unprepare_pwm;
 		}
 
 		ret = clk_prepare(pc->cpt_clk);
 		if (ret) {
 			dev_err(dev, "failed to prepare clock\n");
-			return ret;
+			goto err_unprepare_pwm;
 		}
 	}
 
@@ -645,18 +646,17 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	pc->chip.npwm = pc->cdata->pwm_num_devs;
 
 	ret = pwmchip_add(&pc->chip);
-	if (ret < 0) {
-		clk_unprepare(pc->pwm_clk);
-		clk_unprepare(pc->cpt_clk);
-		return ret;
-	}
+	if (ret < 0)
+		goto err_unprepare_cpt;
 
 	for (i = 0; i < cdata->cpt_num_devs; i++) {
 		struct sti_cpt_ddata *ddata;
 
 		ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
-		if (!ddata)
-			return -ENOMEM;
+		if (!ddata) {
+			ret = -ENOMEM;
+			goto err_remove_pwmchip;
+		}
 
 		init_waitqueue_head(&ddata->wait);
 		mutex_init(&ddata->lock);
@@ -667,6 +667,14 @@ static int sti_pwm_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, pc);
 
 	return 0;
+
+err_remove_pwmchip:
+	pwmchip_remove(&pc->chip);
+err_unprepare_cpt:
+	clk_unprepare(pc->cpt_clk);
+err_unprepare_pwm:
+	clk_unprepare(pc->pwm_clk);
+	return ret;
 }
 
 static void sti_pwm_remove(struct platform_device *pdev)
-- 
2.34.1


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

* Re: [PATCH] pwm: sti: Fix the error handling path of sti_pwm_probe()
  2023-04-16  8:32 [PATCH] pwm: sti: Fix the error handling path of sti_pwm_probe() Christophe JAILLET
@ 2023-04-16 17:02 ` Uwe Kleine-König
  0 siblings, 0 replies; 2+ messages in thread
From: Uwe Kleine-König @ 2023-04-16 17:02 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Thierry Reding, Lee Jones, linux-kernel, kernel-janitors, linux-pwm

[-- Attachment #1: Type: text/plain, Size: 507 bytes --]

Hello,

On Sun, Apr 16, 2023 at 10:32:24AM +0200, Christophe JAILLET wrote:
> Rewrite the error handing path of sti_pwm_probe() to avoid some leaks.

There are also some clk_put()'s missing. See
https://lore.kernel.org/linux-pwm/20201013081531.661528-1-uwe@kleine-koenig.org
for an older fix of the things you noticed.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2023-04-16 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-16  8:32 [PATCH] pwm: sti: Fix the error handling path of sti_pwm_probe() Christophe JAILLET
2023-04-16 17:02 ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).