watchdog: retu_wdt: Clean-up by using managed work init
authorMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Tue, 23 Mar 2021 13:58:28 +0000 (15:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Mar 2021 14:22:40 +0000 (15:22 +0100)
Few drivers implement remove call-back only for ensuring a delayed
work gets cancelled prior driver removal. Clean-up these by switching
to use devm_delayed_work_autocancel() instead.

This change is compile-tested only. All testing is appreciated.

Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/be299515fbee2c311162ca99ea0dbee933044b56.1616506559.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/watchdog/retu_wdt.c

index 258dfcf..2b9017e 100644 (file)
@@ -8,6 +8,7 @@
  * Rewritten by Aaro Koskinen.
  */
 
+#include <linux/devm-helpers.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/device.h>
@@ -127,9 +128,12 @@ static int retu_wdt_probe(struct platform_device *pdev)
        wdev->rdev              = rdev;
        wdev->dev               = &pdev->dev;
 
-       INIT_DELAYED_WORK(&wdev->ping_work, retu_wdt_ping_work);
+       ret = devm_delayed_work_autocancel(&pdev->dev, &wdev->ping_work,
+                                          retu_wdt_ping_work);
+       if (ret)
+               return ret;
 
-       ret = watchdog_register_device(retu_wdt);
+       ret = devm_watchdog_register_device(&pdev->dev, retu_wdt);
        if (ret < 0)
                return ret;
 
@@ -138,25 +142,11 @@ static int retu_wdt_probe(struct platform_device *pdev)
        else
                retu_wdt_ping_enable(wdev);
 
-       platform_set_drvdata(pdev, retu_wdt);
-
-       return 0;
-}
-
-static int retu_wdt_remove(struct platform_device *pdev)
-{
-       struct watchdog_device *wdog = platform_get_drvdata(pdev);
-       struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
-
-       watchdog_unregister_device(wdog);
-       cancel_delayed_work_sync(&wdev->ping_work);
-
        return 0;
 }
 
 static struct platform_driver retu_wdt_driver = {
        .probe          = retu_wdt_probe,
-       .remove         = retu_wdt_remove,
        .driver         = {
                .name   = "retu-wdt",
        },