Message ID | 20230824135514.2661364-2-ruanjinjie@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | watchdog: Use the devm_clk_get_enabled() helper function | expand |
On Thu, Aug 24, 2023 at 09:55:12PM +0800, Jinjie Ruan wrote: > The devm_clk_get_enabled() helper: > - calls devm_clk_get() > - calls clk_prepare_enable() and registers what is needed in order to > call clk_disable_unprepare() when needed, as a managed resource. > > This simplifies the code. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/watchdog/at91sam9_wdt.c | 20 +++++--------------- > 1 file changed, 5 insertions(+), 15 deletions(-) > > diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c > index fed7be246442..b111b28acb94 100644 > --- a/drivers/watchdog/at91sam9_wdt.c > +++ b/drivers/watchdog/at91sam9_wdt.c > @@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev) > if (IS_ERR(wdt->base)) > return PTR_ERR(wdt->base); > > - wdt->sclk = devm_clk_get(&pdev->dev, NULL); > - if (IS_ERR(wdt->sclk)) > - return PTR_ERR(wdt->sclk); > - > - err = clk_prepare_enable(wdt->sclk); > - if (err) { > + wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL); > + if (IS_ERR(wdt->sclk)) { > dev_err(&pdev->dev, "Could not enable slow clock\n"); > - return err; > + return PTR_ERR(wdt->sclk); > } > > if (pdev->dev.of_node) { > err = of_at91wdt_init(pdev->dev.of_node, wdt); > if (err) > - goto err_clk; > + return err; > } > > err = at91_wdt_init(pdev, wdt); > if (err) > - goto err_clk; > + return err; > > platform_set_drvdata(pdev, wdt); > > @@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev) > wdt->wdd.timeout, wdt->nowayout); > > return 0; > - > -err_clk: > - clk_disable_unprepare(wdt->sclk); > - > - return err; > } > > static int __exit at91wdt_remove(struct platform_device *pdev) > @@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev) > > pr_warn("I quit now, hardware will probably reboot!\n"); > del_timer(&wdt->timer); > - clk_disable_unprepare(wdt->sclk); > > return 0; > } > -- > 2.34.1 >
On 8/24/23 16:55, Jinjie Ruan wrote: > The devm_clk_get_enabled() helper: > - calls devm_clk_get() > - calls clk_prepare_enable() and registers what is needed in order to > call clk_disable_unprepare() when needed, as a managed resource. > > This simplifies the code. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Reviewed-by: Claudiu Beznea <claudiu.beznea@tuxon.dev> > --- > drivers/watchdog/at91sam9_wdt.c | 20 +++++--------------- > 1 file changed, 5 insertions(+), 15 deletions(-) > > diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c > index fed7be246442..b111b28acb94 100644 > --- a/drivers/watchdog/at91sam9_wdt.c > +++ b/drivers/watchdog/at91sam9_wdt.c > @@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev) > if (IS_ERR(wdt->base)) > return PTR_ERR(wdt->base); > > - wdt->sclk = devm_clk_get(&pdev->dev, NULL); > - if (IS_ERR(wdt->sclk)) > - return PTR_ERR(wdt->sclk); > - > - err = clk_prepare_enable(wdt->sclk); > - if (err) { > + wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL); > + if (IS_ERR(wdt->sclk)) { > dev_err(&pdev->dev, "Could not enable slow clock\n"); > - return err; > + return PTR_ERR(wdt->sclk); > } > > if (pdev->dev.of_node) { > err = of_at91wdt_init(pdev->dev.of_node, wdt); > if (err) > - goto err_clk; > + return err; > } > > err = at91_wdt_init(pdev, wdt); > if (err) > - goto err_clk; > + return err; > > platform_set_drvdata(pdev, wdt); > > @@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev) > wdt->wdd.timeout, wdt->nowayout); > > return 0; > - > -err_clk: > - clk_disable_unprepare(wdt->sclk); > - > - return err; > } > > static int __exit at91wdt_remove(struct platform_device *pdev) > @@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev) > > pr_warn("I quit now, hardware will probably reboot!\n"); > del_timer(&wdt->timer); > - clk_disable_unprepare(wdt->sclk); > > return 0; > }
diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c index fed7be246442..b111b28acb94 100644 --- a/drivers/watchdog/at91sam9_wdt.c +++ b/drivers/watchdog/at91sam9_wdt.c @@ -348,25 +348,21 @@ static int __init at91wdt_probe(struct platform_device *pdev) if (IS_ERR(wdt->base)) return PTR_ERR(wdt->base); - wdt->sclk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(wdt->sclk)) - return PTR_ERR(wdt->sclk); - - err = clk_prepare_enable(wdt->sclk); - if (err) { + wdt->sclk = devm_clk_get_enabled(&pdev->dev, NULL); + if (IS_ERR(wdt->sclk)) { dev_err(&pdev->dev, "Could not enable slow clock\n"); - return err; + return PTR_ERR(wdt->sclk); } if (pdev->dev.of_node) { err = of_at91wdt_init(pdev->dev.of_node, wdt); if (err) - goto err_clk; + return err; } err = at91_wdt_init(pdev, wdt); if (err) - goto err_clk; + return err; platform_set_drvdata(pdev, wdt); @@ -374,11 +370,6 @@ static int __init at91wdt_probe(struct platform_device *pdev) wdt->wdd.timeout, wdt->nowayout); return 0; - -err_clk: - clk_disable_unprepare(wdt->sclk); - - return err; } static int __exit at91wdt_remove(struct platform_device *pdev) @@ -388,7 +379,6 @@ static int __exit at91wdt_remove(struct platform_device *pdev) pr_warn("I quit now, hardware will probably reboot!\n"); del_timer(&wdt->timer); - clk_disable_unprepare(wdt->sclk); return 0; }
The devm_clk_get_enabled() helper: - calls devm_clk_get() - calls clk_prepare_enable() and registers what is needed in order to call clk_disable_unprepare() when needed, as a managed resource. This simplifies the code. Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- drivers/watchdog/at91sam9_wdt.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)