]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
watchdog: Add a device managed API for watchdog_register_device()
authorNeil Armstrong <narmstrong@baylibre.com>
Fri, 27 May 2016 15:33:54 +0000 (17:33 +0200)
committerWim Van Sebroeck <wim@iguana.be>
Sun, 17 Jul 2016 18:52:40 +0000 (20:52 +0200)
This helps in reducing code in .remove callbacks and sometimes
dropping .remove callbacks entirely.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Documentation/driver-model/devres.txt
drivers/watchdog/watchdog_core.c
include/linux/watchdog.h

index c63eea0c1c8c1b3ffe4c853ea8e834d9cd90205e..589296bdc133e3f422c6d7fe6a992e3ac0802db3 100644 (file)
@@ -357,3 +357,6 @@ SLAVE DMA ENGINE
 
 SPI
   devm_spi_register_master()
+
+WATCHDOG
+  devm_watchdog_register_device()
index 7c3ba58ae1bee52022a0a9a2c06ab2a68f2d6ee9..f4f02d2763ec7ef6ea51c2969051b294c4cb8aef 100644 (file)
@@ -329,6 +329,43 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
 
 EXPORT_SYMBOL_GPL(watchdog_unregister_device);
 
+static void devm_watchdog_unregister_device(struct device *dev, void *res)
+{
+       watchdog_unregister_device(*(struct watchdog_device **)res);
+}
+
+/**
+ * devm_watchdog_register_device() - resource managed watchdog_register_device()
+ * @dev: device that is registering this watchdog device
+ * @wdd: watchdog device
+ *
+ * Managed watchdog_register_device(). For watchdog device registered by this
+ * function,  watchdog_unregister_device() is automatically called on driver
+ * detach. See watchdog_register_device() for more information.
+ */
+int devm_watchdog_register_device(struct device *dev,
+                               struct watchdog_device *wdd)
+{
+       struct watchdog_device **rcwdd;
+       int ret;
+
+       rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*wdd),
+                            GFP_KERNEL);
+       if (!rcwdd)
+               return -ENOMEM;
+
+       ret = watchdog_register_device(wdd);
+       if (!ret) {
+               *rcwdd = wdd;
+               devres_add(dev, rcwdd);
+       } else {
+               devres_free(rcwdd);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(devm_watchdog_register_device);
+
 static int __init watchdog_deferred_registration(void)
 {
        mutex_lock(&wtd_deferred_reg_mutex);
index 51732d6c9555decf5264da14a8d611524fab9b4e..6b75e38b683fc3c7b04a7839c827fed18ab3ca9e 100644 (file)
@@ -180,4 +180,7 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd,
 extern int watchdog_register_device(struct watchdog_device *);
 extern void watchdog_unregister_device(struct watchdog_device *);
 
+/* devres register variant */
+int devm_watchdog_register_device(struct device *dev, struct watchdog_device *);
+
 #endif  /* ifndef _LINUX_WATCHDOG_H */