[PATCH v2] pwm: atmel: Simplify using devm functions
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Fri Jul 28 01:11:05 PDT 2023
For all resources used by the driver there is a devm variant to allocate
these. This simplifies the error path in the probe callback and allows
to drop the remove callback.
While at it also use dev_err_probe() to compact returning an error.
With the remove callback gone, there is no user of driver data left, so
the call to platform_set_drvdata() can also be dropped.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
Hello,
changes compared to (implicit) v1:
- Rebased on pwm/for-next due to conflicts with commit a2f68c7e312f
("pwm: atmel: Enable clk when pwm already enabled in bootloader")
- Adapt changelog as now the error path in probe is still used while it
could be dropped before commit a2f68c7e312f.
Thanks
Uwe
drivers/pwm/pwm-atmel.c | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 03c7810416b8..1f73325d1bea 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -517,15 +517,10 @@ static int atmel_pwm_probe(struct platform_device *pdev)
if (IS_ERR(atmel_pwm->base))
return PTR_ERR(atmel_pwm->base);
- atmel_pwm->clk = devm_clk_get(&pdev->dev, NULL);
+ atmel_pwm->clk = devm_clk_get_prepared(&pdev->dev, NULL);
if (IS_ERR(atmel_pwm->clk))
- return PTR_ERR(atmel_pwm->clk);
-
- ret = clk_prepare(atmel_pwm->clk);
- if (ret) {
- dev_err(&pdev->dev, "failed to prepare PWM clock\n");
- return ret;
- }
+ return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->clk),
+ "failed to get prepared PWM clock\n");
atmel_pwm->chip.dev = &pdev->dev;
atmel_pwm->chip.ops = &atmel_pwm_ops;
@@ -533,42 +528,28 @@ static int atmel_pwm_probe(struct platform_device *pdev)
ret = atmel_pwm_enable_clk_if_on(atmel_pwm, true);
if (ret < 0)
- goto unprepare_clk;
+ return ret;
- ret = pwmchip_add(&atmel_pwm->chip);
+ ret = devm_pwmchip_add(&pdev->dev, &atmel_pwm->chip);
if (ret < 0) {
- dev_err(&pdev->dev, "failed to add PWM chip %d\n", ret);
+ dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
goto disable_clk;
}
- platform_set_drvdata(pdev, atmel_pwm);
-
- return ret;
+ return 0;
disable_clk:
atmel_pwm_enable_clk_if_on(atmel_pwm, false);
-unprepare_clk:
- clk_unprepare(atmel_pwm->clk);
return ret;
}
-static void atmel_pwm_remove(struct platform_device *pdev)
-{
- struct atmel_pwm_chip *atmel_pwm = platform_get_drvdata(pdev);
-
- pwmchip_remove(&atmel_pwm->chip);
-
- clk_unprepare(atmel_pwm->clk);
-}
-
static struct platform_driver atmel_pwm_driver = {
.driver = {
.name = "atmel-pwm",
.of_match_table = of_match_ptr(atmel_pwm_dt_ids),
},
.probe = atmel_pwm_probe,
- .remove_new = atmel_pwm_remove,
};
module_platform_driver(atmel_pwm_driver);
base-commit: a2f68c7e312f94c8f78740449a88e8d7308ab18d
--
2.39.2
More information about the linux-arm-kernel
mailing list