hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/watchdog/watchdog_core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * watchdog_core.c
34 *
....@@ -15,11 +16,6 @@
1516 * Rusty Lynch <rusty@linux.co.intel.com>
1617 * Satyam Sharma <satyam@infradead.org>
1718 * Randy Dunlap <randy.dunlap@oracle.com>
18
- *
19
- * This program is free software; you can redistribute it and/or
20
- * modify it under the terms of the GNU General Public License
21
- * as published by the Free Software Foundation; either version
22
- * 2 of the License, or (at your option) any later version.
2319 *
2420 * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
2521 * admit liability nor provide warranty for any of this software.
....@@ -43,6 +39,10 @@
4339
4440 static DEFINE_IDA(watchdog_ida);
4541
42
+static int stop_on_reboot = -1;
43
+module_param(stop_on_reboot, int, 0444);
44
+MODULE_PARM_DESC(stop_on_reboot, "Stop watchdogs on reboot (0=keep watching, 1=stop)");
45
+
4646 /*
4747 * Deferred Registration infrastructure.
4848 *
....@@ -60,11 +60,10 @@
6060 static LIST_HEAD(wtd_deferred_reg_list);
6161 static bool wtd_deferred_reg_done;
6262
63
-static int watchdog_deferred_registration_add(struct watchdog_device *wdd)
63
+static void watchdog_deferred_registration_add(struct watchdog_device *wdd)
6464 {
6565 list_add_tail(&wdd->deferred,
6666 &wtd_deferred_reg_list);
67
- return 0;
6867 }
6968
7069 static void watchdog_deferred_registration_del(struct watchdog_device *wdd)
....@@ -105,34 +104,48 @@
105104 * timeout module parameter (if it is valid value) or the timeout-sec property
106105 * (only if it is a valid value and the timeout_parm is out of bounds).
107106 * If none of them are valid then we keep the old value (which should normally
108
- * be the default timeout value).
107
+ * be the default timeout value). Note that for the module parameter, '0' means
108
+ * 'use default' while it is an invalid value for the timeout-sec property.
109
+ * It should simply be dropped if you want to use the default value then.
109110 *
110
- * A zero is returned on success and -EINVAL for failure.
111
+ * A zero is returned on success or -EINVAL if all provided values are out of
112
+ * bounds.
111113 */
112114 int watchdog_init_timeout(struct watchdog_device *wdd,
113115 unsigned int timeout_parm, struct device *dev)
114116 {
117
+ const char *dev_str = wdd->parent ? dev_name(wdd->parent) :
118
+ (const char *)wdd->info->identity;
115119 unsigned int t = 0;
116120 int ret = 0;
117121
118122 watchdog_check_min_max_timeout(wdd);
119123
120
- /* try to get the timeout module parameter first */
121
- if (!watchdog_timeout_invalid(wdd, timeout_parm) && timeout_parm) {
122
- wdd->timeout = timeout_parm;
123
- return ret;
124
- }
125
- if (timeout_parm)
124
+ /* check the driver supplied value (likely a module parameter) first */
125
+ if (timeout_parm) {
126
+ if (!watchdog_timeout_invalid(wdd, timeout_parm)) {
127
+ wdd->timeout = timeout_parm;
128
+ return 0;
129
+ }
130
+ pr_err("%s: driver supplied timeout (%u) out of range\n",
131
+ dev_str, timeout_parm);
126132 ret = -EINVAL;
133
+ }
127134
128135 /* try to get the timeout_sec property */
129
- if (dev == NULL || dev->of_node == NULL)
130
- return ret;
131
- of_property_read_u32(dev->of_node, "timeout-sec", &t);
132
- if (!watchdog_timeout_invalid(wdd, t) && t)
133
- wdd->timeout = t;
134
- else
136
+ if (dev && dev->of_node &&
137
+ of_property_read_u32(dev->of_node, "timeout-sec", &t) == 0) {
138
+ if (t && !watchdog_timeout_invalid(wdd, t)) {
139
+ wdd->timeout = t;
140
+ return 0;
141
+ }
142
+ pr_err("%s: DT supplied timeout (%u) out of range\n", dev_str, t);
135143 ret = -EINVAL;
144
+ }
145
+
146
+ if (ret < 0 && wdd->timeout)
147
+ pr_warn("%s: falling back to default timeout (%u)\n", dev_str,
148
+ wdd->timeout);
136149
137150 return ret;
138151 }
....@@ -245,6 +258,14 @@
245258 }
246259 }
247260
261
+ /* Module parameter to force watchdog policy on reboot. */
262
+ if (stop_on_reboot != -1) {
263
+ if (stop_on_reboot)
264
+ set_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
265
+ else
266
+ clear_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
267
+ }
268
+
248269 if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
249270 if (!wdd->ops->stop)
250271 pr_warn("watchdog%d: stop_on_reboot not supported\n", wdd->id);
....@@ -287,14 +308,23 @@
287308
288309 int watchdog_register_device(struct watchdog_device *wdd)
289310 {
290
- int ret;
311
+ const char *dev_str;
312
+ int ret = 0;
291313
292314 mutex_lock(&wtd_deferred_reg_mutex);
293315 if (wtd_deferred_reg_done)
294316 ret = __watchdog_register_device(wdd);
295317 else
296
- ret = watchdog_deferred_registration_add(wdd);
318
+ watchdog_deferred_registration_add(wdd);
297319 mutex_unlock(&wtd_deferred_reg_mutex);
320
+
321
+ if (ret) {
322
+ dev_str = wdd->parent ? dev_name(wdd->parent) :
323
+ (const char *)wdd->info->identity;
324
+ pr_err("%s: failed to register watchdog device (err = %d)\n",
325
+ dev_str, ret);
326
+ }
327
+
298328 return ret;
299329 }
300330 EXPORT_SYMBOL_GPL(watchdog_register_device);