Re: [PATCH 2/7] watchdog: jz4740: Use devm_* functions

From: Guenter Roeck
Date: Thu Dec 28 2017 - 16:03:45 EST


On 12/28/2017 12:22 PM, Paul Cercueil wrote:


Le jeu. 28 dÃc. 2017 Ã 21:19, Guenter Roeck <linux@xxxxxxxxxxxx> a Ãcrit :
On 12/28/2017 11:59 AM, Paul Cercueil wrote:
Hi Guenter,

Le jeu. 28 dÃc. 2017 Ã 18:48, Guenter Roeck <linux@xxxxxxxxxxxx> a Ãcrit :
On 12/28/2017 08:29 AM, Paul Cercueil wrote:
- Use devm_clk_get instead of clk_get
- Use devm_watchdog_register_device instead of watchdog_register_device

Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
---
 drivers/watchdog/jz4740_wdt.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c
index 6955deb100ef..92d6ca8ceb49 100644
--- a/drivers/watchdog/jz4740_wdt.c
+++ b/drivers/watchdog/jz4740_wdt.c
@@ -178,40 +178,29 @@ static int jz4740_wdt_probe(struct platform_device *pdev)
  res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ÂÂÂÂÂ drvdata->base = devm_ioremap_resource(&pdev->dev, res);
-ÂÂÂ if (IS_ERR(drvdata->base)) {
-ÂÂÂÂÂÂÂ ret = PTR_ERR(drvdata->base);
-ÂÂÂÂÂÂÂ goto err_out;
-ÂÂÂ }
+ÂÂÂ if (IS_ERR(drvdata->base))
+ÂÂÂÂÂÂÂ return PTR_ERR(drvdata->base);
 - drvdata->rtc_clk = clk_get(&pdev->dev, "rtc");
+ÂÂÂ drvdata->rtc_clk = devm_clk_get(&pdev->dev, "rtc");
ÂÂÂÂÂ if (IS_ERR(drvdata->rtc_clk)) {
ÂÂÂÂÂÂÂÂÂ dev_err(&pdev->dev, "cannot find RTC clock\n");
-ÂÂÂÂÂÂÂ ret = PTR_ERR(drvdata->rtc_clk);
-ÂÂÂÂÂÂÂ goto err_out;
+ÂÂÂÂÂÂÂ return PTR_ERR(drvdata->rtc_clk);
ÂÂÂÂÂ }
 - ret = watchdog_register_device(&drvdata->wdt);
+ÂÂÂ ret = devm_watchdog_register_device(&pdev->dev, &drvdata->wdt);
ÂÂÂÂÂ if (ret < 0)
-ÂÂÂÂÂÂÂ goto err_disable_clk;
+ÂÂÂÂÂÂÂ return ret;
  platform_set_drvdata(pdev, drvdata);
-ÂÂÂ return 0;
 -err_disable_clk:
-ÂÂÂ clk_put(drvdata->rtc_clk);
-err_out:
-ÂÂÂ return ret;
+ÂÂÂ return 0;
 }
  static int jz4740_wdt_remove(struct platform_device *pdev)
 {
ÂÂÂÂÂ struct jz4740_wdt_drvdata *drvdata = platform_get_drvdata(pdev);
 - jz4740_wdt_stop(&drvdata->wdt);
-ÂÂÂ watchdog_unregister_device(&drvdata->wdt);
-ÂÂÂ clk_put(drvdata->rtc_clk);
-
-ÂÂÂ return 0;
+ÂÂÂ return jz4740_wdt_stop(&drvdata->wdt);

If the watchdog is running, the module can not be unloaded. Even if that wasn't
the case, this defeats both WDIOF_MAGICCLOSE and watchdog_set_nowayout().
Are you sure this is what you want ? If so, please call
watchdog_stop_on_unregister() before registration; this clarifies that this
is what you want, and you can drop the remove function.

Thanks,
Guenter

This patch does not change the behaviour. We always used that driver built-in; what
should the behaviour be when unloading the module? Keep the watchdog hardware running
if configured for 'nowayout'?


One can still unload the driver. If you are fine with bypassing/dfeating nowayout
and WDIOF_MAGICCLOSE, may I ask why those are enabled in the first place ?


Who knows? That code is very old :)

Probably copied from some other driver w/o thinking much about it.

I'm fine with removing the remove() function completely, if you think it makes more sense.


Yes, I do, but I won't insist on it either.

Thanks,
Guenter