pwm: sti: Fix the error handling path of sti_pwm_probe()
Commit Message
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(-)
Comments
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
@@ -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)