watchdog: pnx4008_wdt: Convert to use device managed functions and other improvements
authorGuenter Roeck <linux@roeck-us.net>
Wed, 10 Apr 2019 16:28:03 +0000 (09:28 -0700)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Sun, 5 May 2019 19:02:37 +0000 (21:02 +0200)
Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts
used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/pnx4008_wdt.c

index 24c266a9e1dcaf4db330de63f0b5c5fcfadfea09..f94d844e596cdd423a9b98d7b5162d0ddc82534c 100644 (file)
@@ -183,52 +183,49 @@ static struct watchdog_device pnx4008_wdd = {
        .max_timeout = MAX_HEARTBEAT,
 };
 
+static void pnx4008_clk_disable_unprepare(void *data)
+{
+       clk_disable_unprepare(data);
+}
+
 static int pnx4008_wdt_probe(struct platform_device *pdev)
 {
+       struct device *dev = &pdev->dev;
        int ret = 0;
 
-       watchdog_init_timeout(&pnx4008_wdd, heartbeat, &pdev->dev);
+       watchdog_init_timeout(&pnx4008_wdd, heartbeat, dev);
 
        wdt_base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(wdt_base))
                return PTR_ERR(wdt_base);
 
-       wdt_clk = devm_clk_get(&pdev->dev, NULL);
+       wdt_clk = devm_clk_get(dev, NULL);
        if (IS_ERR(wdt_clk))
                return PTR_ERR(wdt_clk);
 
        ret = clk_prepare_enable(wdt_clk);
        if (ret)
                return ret;
+       ret = devm_add_action_or_reset(dev, pnx4008_clk_disable_unprepare,
+                                      wdt_clk);
+       if (ret)
+               return ret;
 
        pnx4008_wdd.bootstatus = (readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ?
                        WDIOF_CARDRESET : 0;
-       pnx4008_wdd.parent = &pdev->dev;
+       pnx4008_wdd.parent = dev;
        watchdog_set_nowayout(&pnx4008_wdd, nowayout);
        watchdog_set_restart_priority(&pnx4008_wdd, 128);
 
        pnx4008_wdt_stop(&pnx4008_wdd); /* disable for now */
 
-       ret = watchdog_register_device(&pnx4008_wdd);
+       ret = devm_watchdog_register_device(dev, &pnx4008_wdd);
        if (ret < 0) {
-               dev_err(&pdev->dev, "cannot register watchdog device\n");
-               goto disable_clk;
+               dev_err(dev, "cannot register watchdog device\n");
+               return ret;
        }
 
-       dev_info(&pdev->dev, "heartbeat %d sec\n", pnx4008_wdd.timeout);
-
-       return 0;
-
-disable_clk:
-       clk_disable_unprepare(wdt_clk);
-       return ret;
-}
-
-static int pnx4008_wdt_remove(struct platform_device *pdev)
-{
-       watchdog_unregister_device(&pnx4008_wdd);
-
-       clk_disable_unprepare(wdt_clk);
+       dev_info(dev, "heartbeat %d sec\n", pnx4008_wdd.timeout);
 
        return 0;
 }
@@ -247,7 +244,6 @@ static struct platform_driver platform_wdt_driver = {
                .of_match_table = of_match_ptr(pnx4008_wdt_match),
        },
        .probe = pnx4008_wdt_probe,
-       .remove = pnx4008_wdt_remove,
 };
 
 module_platform_driver(platform_wdt_driver);