diff options
-rw-r--r-- | Documentation/driver-model/devres.txt | 3 | ||||
-rw-r--r-- | drivers/watchdog/watchdog_core.c | 37 | ||||
-rw-r--r-- | include/linux/watchdog.h | 3 |
3 files changed, 43 insertions, 0 deletions
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index c63eea0c1c8c..589296bdc133 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -357,3 +357,6 @@ SLAVE DMA ENGINE SPI devm_spi_register_master() + +WATCHDOG + devm_watchdog_register_device() diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 7c3ba58ae1be..f4f02d2763ec 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -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); diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 51732d6c9555..6b75e38b683f 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -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 */ |