Commit cb7efc02c6dbc3bfe9d5d1509ed790fc757e05a9
Committed by
Wim Van Sebroeck
1 parent
9d037a7776
Exists in
master
and in
6 other branches
watchdog: WatchDog Timer Driver Core - use passed watchdog_device
Use the passed watchdog_device instead of the static global variable when testing and setting the status in watchdog_ping, watchdog_start, and watchdog_stop. Note that the callers of these functions are actually passing the static global variable. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Showing 1 changed file with 7 additions and 7 deletions Inline Diff
drivers/watchdog/watchdog_dev.c
1 | /* | 1 | /* |
2 | * watchdog_dev.c | 2 | * watchdog_dev.c |
3 | * | 3 | * |
4 | * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>, | 4 | * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>, |
5 | * All Rights Reserved. | 5 | * All Rights Reserved. |
6 | * | 6 | * |
7 | * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>. | 7 | * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>. |
8 | * | 8 | * |
9 | * | 9 | * |
10 | * This source code is part of the generic code that can be used | 10 | * This source code is part of the generic code that can be used |
11 | * by all the watchdog timer drivers. | 11 | * by all the watchdog timer drivers. |
12 | * | 12 | * |
13 | * This part of the generic code takes care of the following | 13 | * This part of the generic code takes care of the following |
14 | * misc device: /dev/watchdog. | 14 | * misc device: /dev/watchdog. |
15 | * | 15 | * |
16 | * Based on source code of the following authors: | 16 | * Based on source code of the following authors: |
17 | * Matt Domsch <Matt_Domsch@dell.com>, | 17 | * Matt Domsch <Matt_Domsch@dell.com>, |
18 | * Rob Radez <rob@osinvestor.com>, | 18 | * Rob Radez <rob@osinvestor.com>, |
19 | * Rusty Lynch <rusty@linux.co.intel.com> | 19 | * Rusty Lynch <rusty@linux.co.intel.com> |
20 | * Satyam Sharma <satyam@infradead.org> | 20 | * Satyam Sharma <satyam@infradead.org> |
21 | * Randy Dunlap <randy.dunlap@oracle.com> | 21 | * Randy Dunlap <randy.dunlap@oracle.com> |
22 | * | 22 | * |
23 | * This program is free software; you can redistribute it and/or | 23 | * This program is free software; you can redistribute it and/or |
24 | * modify it under the terms of the GNU General Public License | 24 | * modify it under the terms of the GNU General Public License |
25 | * as published by the Free Software Foundation; either version | 25 | * as published by the Free Software Foundation; either version |
26 | * 2 of the License, or (at your option) any later version. | 26 | * 2 of the License, or (at your option) any later version. |
27 | * | 27 | * |
28 | * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw. | 28 | * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw. |
29 | * admit liability nor provide warranty for any of this software. | 29 | * admit liability nor provide warranty for any of this software. |
30 | * This material is provided "AS-IS" and at no charge. | 30 | * This material is provided "AS-IS" and at no charge. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 33 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
34 | 34 | ||
35 | #include <linux/module.h> /* For module stuff/... */ | 35 | #include <linux/module.h> /* For module stuff/... */ |
36 | #include <linux/types.h> /* For standard types (like size_t) */ | 36 | #include <linux/types.h> /* For standard types (like size_t) */ |
37 | #include <linux/errno.h> /* For the -ENODEV/... values */ | 37 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
38 | #include <linux/kernel.h> /* For printk/panic/... */ | 38 | #include <linux/kernel.h> /* For printk/panic/... */ |
39 | #include <linux/fs.h> /* For file operations */ | 39 | #include <linux/fs.h> /* For file operations */ |
40 | #include <linux/watchdog.h> /* For watchdog specific items */ | 40 | #include <linux/watchdog.h> /* For watchdog specific items */ |
41 | #include <linux/miscdevice.h> /* For handling misc devices */ | 41 | #include <linux/miscdevice.h> /* For handling misc devices */ |
42 | #include <linux/init.h> /* For __init/__exit/... */ | 42 | #include <linux/init.h> /* For __init/__exit/... */ |
43 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ | 43 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ |
44 | 44 | ||
45 | /* make sure we only register one /dev/watchdog device */ | 45 | /* make sure we only register one /dev/watchdog device */ |
46 | static unsigned long watchdog_dev_busy; | 46 | static unsigned long watchdog_dev_busy; |
47 | /* the watchdog device behind /dev/watchdog */ | 47 | /* the watchdog device behind /dev/watchdog */ |
48 | static struct watchdog_device *wdd; | 48 | static struct watchdog_device *wdd; |
49 | 49 | ||
50 | /* | 50 | /* |
51 | * watchdog_ping: ping the watchdog. | 51 | * watchdog_ping: ping the watchdog. |
52 | * @wddev: the watchdog device to ping | 52 | * @wddev: the watchdog device to ping |
53 | * | 53 | * |
54 | * If the watchdog has no own ping operation then it needs to be | 54 | * If the watchdog has no own ping operation then it needs to be |
55 | * restarted via the start operation. This wrapper function does | 55 | * restarted via the start operation. This wrapper function does |
56 | * exactly that. | 56 | * exactly that. |
57 | * We only ping when the watchdog device is running. | 57 | * We only ping when the watchdog device is running. |
58 | */ | 58 | */ |
59 | 59 | ||
60 | static int watchdog_ping(struct watchdog_device *wddev) | 60 | static int watchdog_ping(struct watchdog_device *wddev) |
61 | { | 61 | { |
62 | if (test_bit(WDOG_ACTIVE, &wdd->status)) { | 62 | if (test_bit(WDOG_ACTIVE, &wddev->status)) { |
63 | if (wddev->ops->ping) | 63 | if (wddev->ops->ping) |
64 | return wddev->ops->ping(wddev); /* ping the watchdog */ | 64 | return wddev->ops->ping(wddev); /* ping the watchdog */ |
65 | else | 65 | else |
66 | return wddev->ops->start(wddev); /* restart watchdog */ | 66 | return wddev->ops->start(wddev); /* restart watchdog */ |
67 | } | 67 | } |
68 | return 0; | 68 | return 0; |
69 | } | 69 | } |
70 | 70 | ||
71 | /* | 71 | /* |
72 | * watchdog_start: wrapper to start the watchdog. | 72 | * watchdog_start: wrapper to start the watchdog. |
73 | * @wddev: the watchdog device to start | 73 | * @wddev: the watchdog device to start |
74 | * | 74 | * |
75 | * Start the watchdog if it is not active and mark it active. | 75 | * Start the watchdog if it is not active and mark it active. |
76 | * This function returns zero on success or a negative errno code for | 76 | * This function returns zero on success or a negative errno code for |
77 | * failure. | 77 | * failure. |
78 | */ | 78 | */ |
79 | 79 | ||
80 | static int watchdog_start(struct watchdog_device *wddev) | 80 | static int watchdog_start(struct watchdog_device *wddev) |
81 | { | 81 | { |
82 | int err; | 82 | int err; |
83 | 83 | ||
84 | if (!test_bit(WDOG_ACTIVE, &wdd->status)) { | 84 | if (!test_bit(WDOG_ACTIVE, &wddev->status)) { |
85 | err = wddev->ops->start(wddev); | 85 | err = wddev->ops->start(wddev); |
86 | if (err < 0) | 86 | if (err < 0) |
87 | return err; | 87 | return err; |
88 | 88 | ||
89 | set_bit(WDOG_ACTIVE, &wdd->status); | 89 | set_bit(WDOG_ACTIVE, &wddev->status); |
90 | } | 90 | } |
91 | return 0; | 91 | return 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | /* | 94 | /* |
95 | * watchdog_stop: wrapper to stop the watchdog. | 95 | * watchdog_stop: wrapper to stop the watchdog. |
96 | * @wddev: the watchdog device to stop | 96 | * @wddev: the watchdog device to stop |
97 | * | 97 | * |
98 | * Stop the watchdog if it is still active and unmark it active. | 98 | * Stop the watchdog if it is still active and unmark it active. |
99 | * This function returns zero on success or a negative errno code for | 99 | * This function returns zero on success or a negative errno code for |
100 | * failure. | 100 | * failure. |
101 | * If the 'nowayout' feature was set, the watchdog cannot be stopped. | 101 | * If the 'nowayout' feature was set, the watchdog cannot be stopped. |
102 | */ | 102 | */ |
103 | 103 | ||
104 | static int watchdog_stop(struct watchdog_device *wddev) | 104 | static int watchdog_stop(struct watchdog_device *wddev) |
105 | { | 105 | { |
106 | int err = -EBUSY; | 106 | int err = -EBUSY; |
107 | 107 | ||
108 | if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) { | 108 | if (test_bit(WDOG_NO_WAY_OUT, &wddev->status)) { |
109 | pr_info("%s: nowayout prevents watchdog to be stopped!\n", | 109 | pr_info("%s: nowayout prevents watchdog to be stopped!\n", |
110 | wdd->info->identity); | 110 | wddev->info->identity); |
111 | return err; | 111 | return err; |
112 | } | 112 | } |
113 | 113 | ||
114 | if (test_bit(WDOG_ACTIVE, &wdd->status)) { | 114 | if (test_bit(WDOG_ACTIVE, &wddev->status)) { |
115 | err = wddev->ops->stop(wddev); | 115 | err = wddev->ops->stop(wddev); |
116 | if (err < 0) | 116 | if (err < 0) |
117 | return err; | 117 | return err; |
118 | 118 | ||
119 | clear_bit(WDOG_ACTIVE, &wdd->status); | 119 | clear_bit(WDOG_ACTIVE, &wddev->status); |
120 | } | 120 | } |
121 | return 0; | 121 | return 0; |
122 | } | 122 | } |
123 | 123 | ||
124 | /* | 124 | /* |
125 | * watchdog_write: writes to the watchdog. | 125 | * watchdog_write: writes to the watchdog. |
126 | * @file: file from VFS | 126 | * @file: file from VFS |
127 | * @data: user address of data | 127 | * @data: user address of data |
128 | * @len: length of data | 128 | * @len: length of data |
129 | * @ppos: pointer to the file offset | 129 | * @ppos: pointer to the file offset |
130 | * | 130 | * |
131 | * A write to a watchdog device is defined as a keepalive ping. | 131 | * A write to a watchdog device is defined as a keepalive ping. |
132 | * Writing the magic 'V' sequence allows the next close to turn | 132 | * Writing the magic 'V' sequence allows the next close to turn |
133 | * off the watchdog (if 'nowayout' is not set). | 133 | * off the watchdog (if 'nowayout' is not set). |
134 | */ | 134 | */ |
135 | 135 | ||
136 | static ssize_t watchdog_write(struct file *file, const char __user *data, | 136 | static ssize_t watchdog_write(struct file *file, const char __user *data, |
137 | size_t len, loff_t *ppos) | 137 | size_t len, loff_t *ppos) |
138 | { | 138 | { |
139 | size_t i; | 139 | size_t i; |
140 | char c; | 140 | char c; |
141 | 141 | ||
142 | if (len == 0) | 142 | if (len == 0) |
143 | return 0; | 143 | return 0; |
144 | 144 | ||
145 | /* | 145 | /* |
146 | * Note: just in case someone wrote the magic character | 146 | * Note: just in case someone wrote the magic character |
147 | * five months ago... | 147 | * five months ago... |
148 | */ | 148 | */ |
149 | clear_bit(WDOG_ALLOW_RELEASE, &wdd->status); | 149 | clear_bit(WDOG_ALLOW_RELEASE, &wdd->status); |
150 | 150 | ||
151 | /* scan to see whether or not we got the magic character */ | 151 | /* scan to see whether or not we got the magic character */ |
152 | for (i = 0; i != len; i++) { | 152 | for (i = 0; i != len; i++) { |
153 | if (get_user(c, data + i)) | 153 | if (get_user(c, data + i)) |
154 | return -EFAULT; | 154 | return -EFAULT; |
155 | if (c == 'V') | 155 | if (c == 'V') |
156 | set_bit(WDOG_ALLOW_RELEASE, &wdd->status); | 156 | set_bit(WDOG_ALLOW_RELEASE, &wdd->status); |
157 | } | 157 | } |
158 | 158 | ||
159 | /* someone wrote to us, so we send the watchdog a keepalive ping */ | 159 | /* someone wrote to us, so we send the watchdog a keepalive ping */ |
160 | watchdog_ping(wdd); | 160 | watchdog_ping(wdd); |
161 | 161 | ||
162 | return len; | 162 | return len; |
163 | } | 163 | } |
164 | 164 | ||
165 | /* | 165 | /* |
166 | * watchdog_ioctl: handle the different ioctl's for the watchdog device. | 166 | * watchdog_ioctl: handle the different ioctl's for the watchdog device. |
167 | * @file: file handle to the device | 167 | * @file: file handle to the device |
168 | * @cmd: watchdog command | 168 | * @cmd: watchdog command |
169 | * @arg: argument pointer | 169 | * @arg: argument pointer |
170 | * | 170 | * |
171 | * The watchdog API defines a common set of functions for all watchdogs | 171 | * The watchdog API defines a common set of functions for all watchdogs |
172 | * according to their available features. | 172 | * according to their available features. |
173 | */ | 173 | */ |
174 | 174 | ||
175 | static long watchdog_ioctl(struct file *file, unsigned int cmd, | 175 | static long watchdog_ioctl(struct file *file, unsigned int cmd, |
176 | unsigned long arg) | 176 | unsigned long arg) |
177 | { | 177 | { |
178 | void __user *argp = (void __user *)arg; | 178 | void __user *argp = (void __user *)arg; |
179 | int __user *p = argp; | 179 | int __user *p = argp; |
180 | unsigned int val; | 180 | unsigned int val; |
181 | int err; | 181 | int err; |
182 | 182 | ||
183 | if (wdd->ops->ioctl) { | 183 | if (wdd->ops->ioctl) { |
184 | err = wdd->ops->ioctl(wdd, cmd, arg); | 184 | err = wdd->ops->ioctl(wdd, cmd, arg); |
185 | if (err != -ENOIOCTLCMD) | 185 | if (err != -ENOIOCTLCMD) |
186 | return err; | 186 | return err; |
187 | } | 187 | } |
188 | 188 | ||
189 | switch (cmd) { | 189 | switch (cmd) { |
190 | case WDIOC_GETSUPPORT: | 190 | case WDIOC_GETSUPPORT: |
191 | return copy_to_user(argp, wdd->info, | 191 | return copy_to_user(argp, wdd->info, |
192 | sizeof(struct watchdog_info)) ? -EFAULT : 0; | 192 | sizeof(struct watchdog_info)) ? -EFAULT : 0; |
193 | case WDIOC_GETSTATUS: | 193 | case WDIOC_GETSTATUS: |
194 | val = wdd->ops->status ? wdd->ops->status(wdd) : 0; | 194 | val = wdd->ops->status ? wdd->ops->status(wdd) : 0; |
195 | return put_user(val, p); | 195 | return put_user(val, p); |
196 | case WDIOC_GETBOOTSTATUS: | 196 | case WDIOC_GETBOOTSTATUS: |
197 | return put_user(wdd->bootstatus, p); | 197 | return put_user(wdd->bootstatus, p); |
198 | case WDIOC_SETOPTIONS: | 198 | case WDIOC_SETOPTIONS: |
199 | if (get_user(val, p)) | 199 | if (get_user(val, p)) |
200 | return -EFAULT; | 200 | return -EFAULT; |
201 | if (val & WDIOS_DISABLECARD) { | 201 | if (val & WDIOS_DISABLECARD) { |
202 | err = watchdog_stop(wdd); | 202 | err = watchdog_stop(wdd); |
203 | if (err < 0) | 203 | if (err < 0) |
204 | return err; | 204 | return err; |
205 | } | 205 | } |
206 | if (val & WDIOS_ENABLECARD) { | 206 | if (val & WDIOS_ENABLECARD) { |
207 | err = watchdog_start(wdd); | 207 | err = watchdog_start(wdd); |
208 | if (err < 0) | 208 | if (err < 0) |
209 | return err; | 209 | return err; |
210 | } | 210 | } |
211 | return 0; | 211 | return 0; |
212 | case WDIOC_KEEPALIVE: | 212 | case WDIOC_KEEPALIVE: |
213 | if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) | 213 | if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) |
214 | return -EOPNOTSUPP; | 214 | return -EOPNOTSUPP; |
215 | watchdog_ping(wdd); | 215 | watchdog_ping(wdd); |
216 | return 0; | 216 | return 0; |
217 | case WDIOC_SETTIMEOUT: | 217 | case WDIOC_SETTIMEOUT: |
218 | if ((wdd->ops->set_timeout == NULL) || | 218 | if ((wdd->ops->set_timeout == NULL) || |
219 | !(wdd->info->options & WDIOF_SETTIMEOUT)) | 219 | !(wdd->info->options & WDIOF_SETTIMEOUT)) |
220 | return -EOPNOTSUPP; | 220 | return -EOPNOTSUPP; |
221 | if (get_user(val, p)) | 221 | if (get_user(val, p)) |
222 | return -EFAULT; | 222 | return -EFAULT; |
223 | if ((wdd->max_timeout != 0) && | 223 | if ((wdd->max_timeout != 0) && |
224 | (val < wdd->min_timeout || val > wdd->max_timeout)) | 224 | (val < wdd->min_timeout || val > wdd->max_timeout)) |
225 | return -EINVAL; | 225 | return -EINVAL; |
226 | err = wdd->ops->set_timeout(wdd, val); | 226 | err = wdd->ops->set_timeout(wdd, val); |
227 | if (err < 0) | 227 | if (err < 0) |
228 | return err; | 228 | return err; |
229 | wdd->timeout = val; | 229 | wdd->timeout = val; |
230 | /* If the watchdog is active then we send a keepalive ping | 230 | /* If the watchdog is active then we send a keepalive ping |
231 | * to make sure that the watchdog keep's running (and if | 231 | * to make sure that the watchdog keep's running (and if |
232 | * possible that it takes the new timeout) */ | 232 | * possible that it takes the new timeout) */ |
233 | watchdog_ping(wdd); | 233 | watchdog_ping(wdd); |
234 | /* Fall */ | 234 | /* Fall */ |
235 | case WDIOC_GETTIMEOUT: | 235 | case WDIOC_GETTIMEOUT: |
236 | /* timeout == 0 means that we don't know the timeout */ | 236 | /* timeout == 0 means that we don't know the timeout */ |
237 | if (wdd->timeout == 0) | 237 | if (wdd->timeout == 0) |
238 | return -EOPNOTSUPP; | 238 | return -EOPNOTSUPP; |
239 | return put_user(wdd->timeout, p); | 239 | return put_user(wdd->timeout, p); |
240 | default: | 240 | default: |
241 | return -ENOTTY; | 241 | return -ENOTTY; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | /* | 245 | /* |
246 | * watchdog_open: open the /dev/watchdog device. | 246 | * watchdog_open: open the /dev/watchdog device. |
247 | * @inode: inode of device | 247 | * @inode: inode of device |
248 | * @file: file handle to device | 248 | * @file: file handle to device |
249 | * | 249 | * |
250 | * When the /dev/watchdog device gets opened, we start the watchdog. | 250 | * When the /dev/watchdog device gets opened, we start the watchdog. |
251 | * Watch out: the /dev/watchdog device is single open, so we make sure | 251 | * Watch out: the /dev/watchdog device is single open, so we make sure |
252 | * it can only be opened once. | 252 | * it can only be opened once. |
253 | */ | 253 | */ |
254 | 254 | ||
255 | static int watchdog_open(struct inode *inode, struct file *file) | 255 | static int watchdog_open(struct inode *inode, struct file *file) |
256 | { | 256 | { |
257 | int err = -EBUSY; | 257 | int err = -EBUSY; |
258 | 258 | ||
259 | /* the watchdog is single open! */ | 259 | /* the watchdog is single open! */ |
260 | if (test_and_set_bit(WDOG_DEV_OPEN, &wdd->status)) | 260 | if (test_and_set_bit(WDOG_DEV_OPEN, &wdd->status)) |
261 | return -EBUSY; | 261 | return -EBUSY; |
262 | 262 | ||
263 | /* | 263 | /* |
264 | * If the /dev/watchdog device is open, we don't want the module | 264 | * If the /dev/watchdog device is open, we don't want the module |
265 | * to be unloaded. | 265 | * to be unloaded. |
266 | */ | 266 | */ |
267 | if (!try_module_get(wdd->ops->owner)) | 267 | if (!try_module_get(wdd->ops->owner)) |
268 | goto out; | 268 | goto out; |
269 | 269 | ||
270 | err = watchdog_start(wdd); | 270 | err = watchdog_start(wdd); |
271 | if (err < 0) | 271 | if (err < 0) |
272 | goto out_mod; | 272 | goto out_mod; |
273 | 273 | ||
274 | /* dev/watchdog is a virtual (and thus non-seekable) filesystem */ | 274 | /* dev/watchdog is a virtual (and thus non-seekable) filesystem */ |
275 | return nonseekable_open(inode, file); | 275 | return nonseekable_open(inode, file); |
276 | 276 | ||
277 | out_mod: | 277 | out_mod: |
278 | module_put(wdd->ops->owner); | 278 | module_put(wdd->ops->owner); |
279 | out: | 279 | out: |
280 | clear_bit(WDOG_DEV_OPEN, &wdd->status); | 280 | clear_bit(WDOG_DEV_OPEN, &wdd->status); |
281 | return err; | 281 | return err; |
282 | } | 282 | } |
283 | 283 | ||
284 | /* | 284 | /* |
285 | * watchdog_release: release the /dev/watchdog device. | 285 | * watchdog_release: release the /dev/watchdog device. |
286 | * @inode: inode of device | 286 | * @inode: inode of device |
287 | * @file: file handle to device | 287 | * @file: file handle to device |
288 | * | 288 | * |
289 | * This is the code for when /dev/watchdog gets closed. We will only | 289 | * This is the code for when /dev/watchdog gets closed. We will only |
290 | * stop the watchdog when we have received the magic char (and nowayout | 290 | * stop the watchdog when we have received the magic char (and nowayout |
291 | * was not set), else the watchdog will keep running. | 291 | * was not set), else the watchdog will keep running. |
292 | */ | 292 | */ |
293 | 293 | ||
294 | static int watchdog_release(struct inode *inode, struct file *file) | 294 | static int watchdog_release(struct inode *inode, struct file *file) |
295 | { | 295 | { |
296 | int err = -EBUSY; | 296 | int err = -EBUSY; |
297 | 297 | ||
298 | /* | 298 | /* |
299 | * We only stop the watchdog if we received the magic character | 299 | * We only stop the watchdog if we received the magic character |
300 | * or if WDIOF_MAGICCLOSE is not set. If nowayout was set then | 300 | * or if WDIOF_MAGICCLOSE is not set. If nowayout was set then |
301 | * watchdog_stop will fail. | 301 | * watchdog_stop will fail. |
302 | */ | 302 | */ |
303 | if (test_and_clear_bit(WDOG_ALLOW_RELEASE, &wdd->status) || | 303 | if (test_and_clear_bit(WDOG_ALLOW_RELEASE, &wdd->status) || |
304 | !(wdd->info->options & WDIOF_MAGICCLOSE)) | 304 | !(wdd->info->options & WDIOF_MAGICCLOSE)) |
305 | err = watchdog_stop(wdd); | 305 | err = watchdog_stop(wdd); |
306 | 306 | ||
307 | /* If the watchdog was not stopped, send a keepalive ping */ | 307 | /* If the watchdog was not stopped, send a keepalive ping */ |
308 | if (err < 0) { | 308 | if (err < 0) { |
309 | pr_crit("%s: watchdog did not stop!\n", wdd->info->identity); | 309 | pr_crit("%s: watchdog did not stop!\n", wdd->info->identity); |
310 | watchdog_ping(wdd); | 310 | watchdog_ping(wdd); |
311 | } | 311 | } |
312 | 312 | ||
313 | /* Allow the owner module to be unloaded again */ | 313 | /* Allow the owner module to be unloaded again */ |
314 | module_put(wdd->ops->owner); | 314 | module_put(wdd->ops->owner); |
315 | 315 | ||
316 | /* make sure that /dev/watchdog can be re-opened */ | 316 | /* make sure that /dev/watchdog can be re-opened */ |
317 | clear_bit(WDOG_DEV_OPEN, &wdd->status); | 317 | clear_bit(WDOG_DEV_OPEN, &wdd->status); |
318 | 318 | ||
319 | return 0; | 319 | return 0; |
320 | } | 320 | } |
321 | 321 | ||
322 | static const struct file_operations watchdog_fops = { | 322 | static const struct file_operations watchdog_fops = { |
323 | .owner = THIS_MODULE, | 323 | .owner = THIS_MODULE, |
324 | .write = watchdog_write, | 324 | .write = watchdog_write, |
325 | .unlocked_ioctl = watchdog_ioctl, | 325 | .unlocked_ioctl = watchdog_ioctl, |
326 | .open = watchdog_open, | 326 | .open = watchdog_open, |
327 | .release = watchdog_release, | 327 | .release = watchdog_release, |
328 | }; | 328 | }; |
329 | 329 | ||
330 | static struct miscdevice watchdog_miscdev = { | 330 | static struct miscdevice watchdog_miscdev = { |
331 | .minor = WATCHDOG_MINOR, | 331 | .minor = WATCHDOG_MINOR, |
332 | .name = "watchdog", | 332 | .name = "watchdog", |
333 | .fops = &watchdog_fops, | 333 | .fops = &watchdog_fops, |
334 | }; | 334 | }; |
335 | 335 | ||
336 | /* | 336 | /* |
337 | * watchdog_dev_register: | 337 | * watchdog_dev_register: |
338 | * @watchdog: watchdog device | 338 | * @watchdog: watchdog device |
339 | * | 339 | * |
340 | * Register a watchdog device as /dev/watchdog. /dev/watchdog | 340 | * Register a watchdog device as /dev/watchdog. /dev/watchdog |
341 | * is actually a miscdevice and thus we set it up like that. | 341 | * is actually a miscdevice and thus we set it up like that. |
342 | */ | 342 | */ |
343 | 343 | ||
344 | int watchdog_dev_register(struct watchdog_device *watchdog) | 344 | int watchdog_dev_register(struct watchdog_device *watchdog) |
345 | { | 345 | { |
346 | int err; | 346 | int err; |
347 | 347 | ||
348 | /* Only one device can register for /dev/watchdog */ | 348 | /* Only one device can register for /dev/watchdog */ |
349 | if (test_and_set_bit(0, &watchdog_dev_busy)) { | 349 | if (test_and_set_bit(0, &watchdog_dev_busy)) { |
350 | pr_err("only one watchdog can use /dev/watchdog.\n"); | 350 | pr_err("only one watchdog can use /dev/watchdog.\n"); |
351 | return -EBUSY; | 351 | return -EBUSY; |
352 | } | 352 | } |
353 | 353 | ||
354 | wdd = watchdog; | 354 | wdd = watchdog; |
355 | 355 | ||
356 | err = misc_register(&watchdog_miscdev); | 356 | err = misc_register(&watchdog_miscdev); |
357 | if (err != 0) { | 357 | if (err != 0) { |
358 | pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n", | 358 | pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n", |
359 | watchdog->info->identity, WATCHDOG_MINOR, err); | 359 | watchdog->info->identity, WATCHDOG_MINOR, err); |
360 | goto out; | 360 | goto out; |
361 | } | 361 | } |
362 | 362 | ||
363 | return 0; | 363 | return 0; |
364 | 364 | ||
365 | out: | 365 | out: |
366 | wdd = NULL; | 366 | wdd = NULL; |
367 | clear_bit(0, &watchdog_dev_busy); | 367 | clear_bit(0, &watchdog_dev_busy); |
368 | return err; | 368 | return err; |
369 | } | 369 | } |
370 | 370 | ||
371 | /* | 371 | /* |
372 | * watchdog_dev_unregister: | 372 | * watchdog_dev_unregister: |
373 | * @watchdog: watchdog device | 373 | * @watchdog: watchdog device |
374 | * | 374 | * |
375 | * Deregister the /dev/watchdog device. | 375 | * Deregister the /dev/watchdog device. |
376 | */ | 376 | */ |
377 | 377 | ||
378 | int watchdog_dev_unregister(struct watchdog_device *watchdog) | 378 | int watchdog_dev_unregister(struct watchdog_device *watchdog) |
379 | { | 379 | { |
380 | /* Check that a watchdog device was registered in the past */ | 380 | /* Check that a watchdog device was registered in the past */ |
381 | if (!test_bit(0, &watchdog_dev_busy) || !wdd) | 381 | if (!test_bit(0, &watchdog_dev_busy) || !wdd) |
382 | return -ENODEV; | 382 | return -ENODEV; |
383 | 383 | ||
384 | /* We can only unregister the watchdog device that was registered */ | 384 | /* We can only unregister the watchdog device that was registered */ |
385 | if (watchdog != wdd) { | 385 | if (watchdog != wdd) { |
386 | pr_err("%s: watchdog was not registered as /dev/watchdog.\n", | 386 | pr_err("%s: watchdog was not registered as /dev/watchdog.\n", |
387 | watchdog->info->identity); | 387 | watchdog->info->identity); |
388 | return -ENODEV; | 388 | return -ENODEV; |
389 | } | 389 | } |
390 | 390 | ||
391 | misc_deregister(&watchdog_miscdev); | 391 | misc_deregister(&watchdog_miscdev); |
392 | wdd = NULL; | 392 | wdd = NULL; |
393 | clear_bit(0, &watchdog_dev_busy); | 393 | clear_bit(0, &watchdog_dev_busy); |
394 | return 0; | 394 | return 0; |
395 | } | 395 | } |
396 | 396 |