summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Armstrong <narmstrong@baylibre.com>2016-05-27 11:33:54 -0400
committerWim Van Sebroeck <wim@iguana.be>2016-07-17 14:52:40 -0400
commit83fbae5a148cc1cd53e5be1a28edb3b6701b7af2 (patch)
tree70ee9bebd8aa953e3508980ed0227beed9805e21
parent47ef4ad2684d380dd6d596140fb79395115c3950 (diff)
watchdog: Add a device managed API for watchdog_register_device()
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>
-rw-r--r--Documentation/driver-model/devres.txt3
-rw-r--r--drivers/watchdog/watchdog_core.c37
-rw-r--r--include/linux/watchdog.h3
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
357 357
358SPI 358SPI
359 devm_spi_register_master() 359 devm_spi_register_master()
360
361WATCHDOG
362 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)
329 329
330EXPORT_SYMBOL_GPL(watchdog_unregister_device); 330EXPORT_SYMBOL_GPL(watchdog_unregister_device);
331 331
332static void devm_watchdog_unregister_device(struct device *dev, void *res)
333{
334 watchdog_unregister_device(*(struct watchdog_device **)res);
335}
336
337/**
338 * devm_watchdog_register_device() - resource managed watchdog_register_device()
339 * @dev: device that is registering this watchdog device
340 * @wdd: watchdog device
341 *
342 * Managed watchdog_register_device(). For watchdog device registered by this
343 * function, watchdog_unregister_device() is automatically called on driver
344 * detach. See watchdog_register_device() for more information.
345 */
346int devm_watchdog_register_device(struct device *dev,
347 struct watchdog_device *wdd)
348{
349 struct watchdog_device **rcwdd;
350 int ret;
351
352 rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*wdd),
353 GFP_KERNEL);
354 if (!rcwdd)
355 return -ENOMEM;
356
357 ret = watchdog_register_device(wdd);
358 if (!ret) {
359 *rcwdd = wdd;
360 devres_add(dev, rcwdd);
361 } else {
362 devres_free(rcwdd);
363 }
364
365 return ret;
366}
367EXPORT_SYMBOL_GPL(devm_watchdog_register_device);
368
332static int __init watchdog_deferred_registration(void) 369static int __init watchdog_deferred_registration(void)
333{ 370{
334 mutex_lock(&wtd_deferred_reg_mutex); 371 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,
180extern int watchdog_register_device(struct watchdog_device *); 180extern int watchdog_register_device(struct watchdog_device *);
181extern void watchdog_unregister_device(struct watchdog_device *); 181extern void watchdog_unregister_device(struct watchdog_device *);
182 182
183/* devres register variant */
184int devm_watchdog_register_device(struct device *dev, struct watchdog_device *);
185
183#endif /* ifndef _LINUX_WATCHDOG_H */ 186#endif /* ifndef _LINUX_WATCHDOG_H */