diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2017-11-17 18:31:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-17 19:10:04 -0500 |
commit | 44ea39420fc95e7432ddc91de4eb58c7470ab897 (patch) | |
tree | 046d89fe44f3874baf9242dea3d34bb991c4c2b4 | |
parent | 2d8364bae4db144df75ba85e92d2b8619ba8eedc (diff) |
drivers/watchdog: make use of devm_register_reboot_notifier()
Save a bit of cleanup code by leveraging newly added
devm_register_reboot_notifier().
[akpm@linux-foundation.org: small cleanup: avoid 80-col tricks]
Link: http://lkml.kernel.org/r/20170411160615.9784-1-andrew.smirnov@gmail.com
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Wim Van Sebroeck <wim@iguana.be>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/watchdog/watchdog_core.c | 35 | ||||
-rw-r--r-- | drivers/watchdog/watchdog_dev.c | 32 |
2 files changed, 32 insertions, 35 deletions
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 74265b2f806c..8a8d952f8df9 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c | |||
@@ -137,25 +137,6 @@ int watchdog_init_timeout(struct watchdog_device *wdd, | |||
137 | } | 137 | } |
138 | EXPORT_SYMBOL_GPL(watchdog_init_timeout); | 138 | EXPORT_SYMBOL_GPL(watchdog_init_timeout); |
139 | 139 | ||
140 | static int watchdog_reboot_notifier(struct notifier_block *nb, | ||
141 | unsigned long code, void *data) | ||
142 | { | ||
143 | struct watchdog_device *wdd = container_of(nb, struct watchdog_device, | ||
144 | reboot_nb); | ||
145 | |||
146 | if (code == SYS_DOWN || code == SYS_HALT) { | ||
147 | if (watchdog_active(wdd)) { | ||
148 | int ret; | ||
149 | |||
150 | ret = wdd->ops->stop(wdd); | ||
151 | if (ret) | ||
152 | return NOTIFY_BAD; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return NOTIFY_DONE; | ||
157 | } | ||
158 | |||
159 | static int watchdog_restart_notifier(struct notifier_block *nb, | 140 | static int watchdog_restart_notifier(struct notifier_block *nb, |
160 | unsigned long action, void *data) | 141 | unsigned long action, void *data) |
161 | { | 142 | { |
@@ -244,19 +225,6 @@ static int __watchdog_register_device(struct watchdog_device *wdd) | |||
244 | } | 225 | } |
245 | } | 226 | } |
246 | 227 | ||
247 | if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { | ||
248 | wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; | ||
249 | |||
250 | ret = register_reboot_notifier(&wdd->reboot_nb); | ||
251 | if (ret) { | ||
252 | pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", | ||
253 | wdd->id, ret); | ||
254 | watchdog_dev_unregister(wdd); | ||
255 | ida_simple_remove(&watchdog_ida, wdd->id); | ||
256 | return ret; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | if (wdd->ops->restart) { | 228 | if (wdd->ops->restart) { |
261 | wdd->restart_nb.notifier_call = watchdog_restart_notifier; | 229 | wdd->restart_nb.notifier_call = watchdog_restart_notifier; |
262 | 230 | ||
@@ -302,9 +270,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd) | |||
302 | if (wdd->ops->restart) | 270 | if (wdd->ops->restart) |
303 | unregister_restart_handler(&wdd->restart_nb); | 271 | unregister_restart_handler(&wdd->restart_nb); |
304 | 272 | ||
305 | if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) | ||
306 | unregister_reboot_notifier(&wdd->reboot_nb); | ||
307 | |||
308 | watchdog_dev_unregister(wdd); | 273 | watchdog_dev_unregister(wdd); |
309 | ida_simple_remove(&watchdog_ida, wdd->id); | 274 | ida_simple_remove(&watchdog_ida, wdd->id); |
310 | } | 275 | } |
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 0826e663bd5a..1e971a50d7fb 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/miscdevice.h> /* For handling misc devices */ | 42 | #include <linux/miscdevice.h> /* For handling misc devices */ |
43 | #include <linux/module.h> /* For module stuff/... */ | 43 | #include <linux/module.h> /* For module stuff/... */ |
44 | #include <linux/mutex.h> /* For mutexes */ | 44 | #include <linux/mutex.h> /* For mutexes */ |
45 | #include <linux/reboot.h> /* For reboot notifier */ | ||
45 | #include <linux/slab.h> /* For memory functions */ | 46 | #include <linux/slab.h> /* For memory functions */ |
46 | #include <linux/types.h> /* For standard types (like size_t) */ | 47 | #include <linux/types.h> /* For standard types (like size_t) */ |
47 | #include <linux/watchdog.h> /* For watchdog specific items */ | 48 | #include <linux/watchdog.h> /* For watchdog specific items */ |
@@ -1016,6 +1017,25 @@ static struct class watchdog_class = { | |||
1016 | .dev_groups = wdt_groups, | 1017 | .dev_groups = wdt_groups, |
1017 | }; | 1018 | }; |
1018 | 1019 | ||
1020 | static int watchdog_reboot_notifier(struct notifier_block *nb, | ||
1021 | unsigned long code, void *data) | ||
1022 | { | ||
1023 | struct watchdog_device *wdd; | ||
1024 | |||
1025 | wdd = container_of(nb, struct watchdog_device, reboot_nb); | ||
1026 | if (code == SYS_DOWN || code == SYS_HALT) { | ||
1027 | if (watchdog_active(wdd)) { | ||
1028 | int ret; | ||
1029 | |||
1030 | ret = wdd->ops->stop(wdd); | ||
1031 | if (ret) | ||
1032 | return NOTIFY_BAD; | ||
1033 | } | ||
1034 | } | ||
1035 | |||
1036 | return NOTIFY_DONE; | ||
1037 | } | ||
1038 | |||
1019 | /* | 1039 | /* |
1020 | * watchdog_dev_register: register a watchdog device | 1040 | * watchdog_dev_register: register a watchdog device |
1021 | * @wdd: watchdog device | 1041 | * @wdd: watchdog device |
@@ -1049,6 +1069,18 @@ int watchdog_dev_register(struct watchdog_device *wdd) | |||
1049 | if (ret) { | 1069 | if (ret) { |
1050 | device_destroy(&watchdog_class, devno); | 1070 | device_destroy(&watchdog_class, devno); |
1051 | watchdog_cdev_unregister(wdd); | 1071 | watchdog_cdev_unregister(wdd); |
1072 | return ret; | ||
1073 | } | ||
1074 | |||
1075 | if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { | ||
1076 | wdd->reboot_nb.notifier_call = watchdog_reboot_notifier; | ||
1077 | |||
1078 | ret = devm_register_reboot_notifier(dev, &wdd->reboot_nb); | ||
1079 | if (ret) { | ||
1080 | pr_err("watchdog%d: Cannot register reboot notifier (%d)\n", | ||
1081 | wdd->id, ret); | ||
1082 | watchdog_dev_unregister(wdd); | ||
1083 | } | ||
1052 | } | 1084 | } |
1053 | 1085 | ||
1054 | return ret; | 1086 | return ret; |