* [PATCH] pwm: atmel: Simplify using devm functions
@ 2023-07-19 19:32 Uwe Kleine-König
2023-07-28 7:34 ` Thierry Reding
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2023-07-19 19:32 UTC (permalink / raw)
To: Claudiu Beznea, Thierry Reding, Nicolas Ferre, Alexandre Belloni
Cc: linux-arm-kernel, linux-pwm
For all resources used by the driver there is a devm variant to allocate
these. This makes it unnecessary to implement an error path or a remove
function.
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@pengutronix.de>
---
drivers/pwm/pwm-atmel.c | 38 ++++++++------------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 5f7d286871cf..ade0331159f7 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -482,42 +482,21 @@ 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;
atmel_pwm->chip.npwm = 4;
- ret = pwmchip_add(&atmel_pwm->chip);
- if (ret < 0) {
- dev_err(&pdev->dev, "failed to add PWM chip %d\n", ret);
- goto unprepare_clk;
- }
+ ret = devm_pwmchip_add(&pdev->dev, &atmel_pwm->chip);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret,
+ "failed to add PWM chip\n");
- platform_set_drvdata(pdev, atmel_pwm);
-
- return ret;
-
-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);
+ return 0;
}
static struct platform_driver atmel_pwm_driver = {
@@ -526,7 +505,6 @@ static struct platform_driver atmel_pwm_driver = {
.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: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
--
2.39.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] pwm: atmel: Simplify using devm functions
2023-07-19 19:32 [PATCH] pwm: atmel: Simplify using devm functions Uwe Kleine-König
@ 2023-07-28 7:34 ` Thierry Reding
0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2023-07-28 7:34 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: linux-pwm, Alexandre Belloni, Claudiu Beznea, linux-arm-kernel
[-- Attachment #1.1: Type: text/plain, Size: 717 bytes --]
On Wed, Jul 19, 2023 at 09:32:13PM +0200, Uwe Kleine-König wrote:
> For all resources used by the driver there is a devm variant to allocate
> these. This makes it unnecessary to implement an error path or a remove
> function.
>
> 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@pengutronix.de>
> ---
> drivers/pwm/pwm-atmel.c | 38 ++++++++------------------------------
> 1 file changed, 8 insertions(+), 30 deletions(-)
Doesn't apply to the for-next branch, please rebase.
Thierry
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-28 7:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 19:32 [PATCH] pwm: atmel: Simplify using devm functions Uwe Kleine-König
2023-07-28 7:34 ` Thierry Reding
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).