23
23
* Added KERN_* tags to printks
24
24
* add CONFIG_WATCHDOG_NOWAYOUT support
25
25
* fix possible wdt_is_open race
26
- * changed watchdog_info to correctly reflect what the driver offers
27
- * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS, WDIOC_SETTIMEOUT,
26
+ * changed watchdog_info to correctly reflect what
27
+ * the driver offers
28
+ * added WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS,
29
+ * WDIOC_SETTIMEOUT,
28
30
* WDIOC_GETTIMEOUT, and WDIOC_SETOPTIONS ioctls
29
31
* 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces
30
32
* added extra printk's for startup problems
31
33
* use module_param
32
- * made timeout (the emulated heartbeat) a module_param
34
+ * made timeout (the emulated heartbeat) a
35
+ * module_param
33
36
* made the keepalive ping an internal subroutine
34
37
*
35
38
* This WDT driver is different from most other Linux WDT
51
54
#include <linux/notifier.h>
52
55
#include <linux/reboot.h>
53
56
#include <linux/init.h>
54
- #include <asm /io.h>
55
- #include <asm /uaccess.h>
57
+ #include <linux /io.h>
58
+ #include <linux /uaccess.h>
56
59
#include <asm/system.h>
57
60
58
61
#define OUR_NAME "w83877f_wdt"
80
83
*/
81
84
82
85
#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
83
- static int timeout = WATCHDOG_TIMEOUT ; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
86
+ /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
87
+ static int timeout = WATCHDOG_TIMEOUT ;
84
88
module_param (timeout , int , 0 );
85
- MODULE_PARM_DESC (timeout , "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING (WATCHDOG_TIMEOUT ) ")" );
89
+ MODULE_PARM_DESC (timeout ,
90
+ "Watchdog timeout in seconds. (1<=timeout<=3600, default="
91
+ __MODULE_STRING (WATCHDOG_TIMEOUT ) ")" );
86
92
87
93
88
94
static int nowayout = WATCHDOG_NOWAYOUT ;
89
95
module_param (nowayout , int , 0 );
90
- MODULE_PARM_DESC (nowayout , "Watchdog cannot be stopped once started (default=" __MODULE_STRING (WATCHDOG_NOWAYOUT ) ")" );
96
+ MODULE_PARM_DESC (nowayout ,
97
+ "Watchdog cannot be stopped once started (default="
98
+ __MODULE_STRING (WATCHDOG_NOWAYOUT ) ")" );
91
99
92
100
static void wdt_timer_ping (unsigned long );
93
101
static DEFINE_TIMER (timer , wdt_timer_ping , 0 , 0 ) ;
@@ -105,8 +113,7 @@ static void wdt_timer_ping(unsigned long data)
105
113
/* If we got a heartbeat pulse within the WDT_US_INTERVAL
106
114
* we agree to ping the WDT
107
115
*/
108
- if (time_before (jiffies , next_heartbeat ))
109
- {
116
+ if (time_before (jiffies , next_heartbeat )) {
110
117
/* Ping the WDT */
111
118
spin_lock (& wdt_spinlock );
112
119
@@ -118,9 +125,9 @@ static void wdt_timer_ping(unsigned long data)
118
125
119
126
spin_unlock (& wdt_spinlock );
120
127
121
- } else {
122
- printk (KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n" );
123
- }
128
+ } else
129
+ printk (KERN_WARNING PFX
130
+ "Heartbeat lost! Will not ping the watchdog\n" );
124
131
}
125
132
126
133
/*
@@ -181,22 +188,21 @@ static void wdt_keepalive(void)
181
188
* /dev/watchdog handling
182
189
*/
183
190
184
- static ssize_t fop_write (struct file * file , const char __user * buf , size_t count , loff_t * ppos )
191
+ static ssize_t fop_write (struct file * file , const char __user * buf ,
192
+ size_t count , loff_t * ppos )
185
193
{
186
194
/* See if we got the magic character 'V' and reload the timer */
187
- if (count )
188
- {
189
- if (!nowayout )
190
- {
195
+ if (count ) {
196
+ if (!nowayout ) {
191
197
size_t ofs ;
192
198
193
- /* note: just in case someone wrote the magic character
194
- * five months ago... */
199
+ /* note: just in case someone wrote the magic
200
+ character five months ago... */
195
201
wdt_expect_close = 0 ;
196
202
197
- /* scan to see whether or not we got the magic character */
198
- for ( ofs = 0 ; ofs != count ; ofs ++ )
199
- {
203
+ /* scan to see whether or not we got the
204
+ magic character */
205
+ for ( ofs = 0 ; ofs != count ; ofs ++ ) {
200
206
char c ;
201
207
if (get_user (c , buf + ofs ))
202
208
return - EFAULT ;
@@ -211,89 +217,89 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou
211
217
return count ;
212
218
}
213
219
214
- static int fop_open (struct inode * inode , struct file * file )
220
+ static int fop_open (struct inode * inode , struct file * file )
215
221
{
216
222
/* Just in case we're already talking to someone... */
217
- if (test_and_set_bit (0 , & wdt_is_open ))
223
+ if (test_and_set_bit (0 , & wdt_is_open ))
218
224
return - EBUSY ;
219
225
220
226
/* Good, fire up the show */
221
227
wdt_startup ();
222
228
return nonseekable_open (inode , file );
223
229
}
224
230
225
- static int fop_close (struct inode * inode , struct file * file )
231
+ static int fop_close (struct inode * inode , struct file * file )
226
232
{
227
- if (wdt_expect_close == 42 )
233
+ if (wdt_expect_close == 42 )
228
234
wdt_turnoff ();
229
235
else {
230
236
del_timer (& timer );
231
- printk (KERN_CRIT PFX "device file closed unexpectedly. Will not stop the WDT!\n" );
237
+ printk (KERN_CRIT PFX
238
+ "device file closed unexpectedly. Will not stop the WDT!\n" );
232
239
}
233
240
clear_bit (0 , & wdt_is_open );
234
241
wdt_expect_close = 0 ;
235
242
return 0 ;
236
243
}
237
244
238
- static int fop_ioctl (struct inode * inode , struct file * file , unsigned int cmd ,
239
- unsigned long arg )
245
+ static long fop_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
240
246
{
241
247
void __user * argp = (void __user * )arg ;
242
248
int __user * p = argp ;
243
- static struct watchdog_info ident =
244
- {
245
- . options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE ,
249
+ static const struct watchdog_info ident = {
250
+ . options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
251
+ | WDIOF_MAGICCLOSE ,
246
252
.firmware_version = 1 ,
247
253
.identity = "W83877F" ,
248
254
};
249
255
250
- switch (cmd )
256
+ switch (cmd ) {
257
+ default :
258
+ return - ENOTTY ;
259
+ case WDIOC_GETSUPPORT :
260
+ return copy_to_user (argp , & ident , sizeof (ident )) ? - EFAULT : 0 ;
261
+ case WDIOC_GETSTATUS :
262
+ case WDIOC_GETBOOTSTATUS :
263
+ return put_user (0 , p );
264
+ case WDIOC_KEEPALIVE :
265
+ wdt_keepalive ();
266
+ return 0 ;
267
+ case WDIOC_SETOPTIONS :
251
268
{
252
- default :
253
- return - ENOTTY ;
254
- case WDIOC_GETSUPPORT :
255
- return copy_to_user (argp , & ident , sizeof (ident ))?- EFAULT :0 ;
256
- case WDIOC_GETSTATUS :
257
- case WDIOC_GETBOOTSTATUS :
258
- return put_user (0 , p );
259
- case WDIOC_KEEPALIVE :
260
- wdt_keepalive ();
261
- return 0 ;
262
- case WDIOC_SETOPTIONS :
263
- {
264
- int new_options , retval = - EINVAL ;
265
-
266
- if (get_user (new_options , p ))
267
- return - EFAULT ;
268
-
269
- if (new_options & WDIOS_DISABLECARD ) {
270
- wdt_turnoff ();
271
- retval = 0 ;
272
- }
269
+ int new_options , retval = - EINVAL ;
273
270
274
- if (new_options & WDIOS_ENABLECARD ) {
275
- wdt_startup ();
276
- retval = 0 ;
277
- }
271
+ if (get_user (new_options , p ))
272
+ return - EFAULT ;
278
273
279
- return retval ;
274
+ if (new_options & WDIOS_DISABLECARD ) {
275
+ wdt_turnoff ();
276
+ retval = 0 ;
280
277
}
281
- case WDIOC_SETTIMEOUT :
282
- {
283
- int new_timeout ;
284
278
285
- if (get_user (new_timeout , p ))
286
- return - EFAULT ;
279
+ if (new_options & WDIOS_ENABLECARD ) {
280
+ wdt_startup ();
281
+ retval = 0 ;
282
+ }
287
283
288
- if (new_timeout < 1 || new_timeout > 3600 ) /* arbitrary upper limit */
289
- return - EINVAL ;
284
+ return retval ;
285
+ }
286
+ case WDIOC_SETTIMEOUT :
287
+ {
288
+ int new_timeout ;
290
289
291
- timeout = new_timeout ;
292
- wdt_keepalive ();
293
- /* Fall through */
294
- }
295
- case WDIOC_GETTIMEOUT :
296
- return put_user (timeout , p );
290
+ if (get_user (new_timeout , p ))
291
+ return - EFAULT ;
292
+
293
+ /* arbitrary upper limit */
294
+ if (new_timeout < 1 || new_timeout > 3600 )
295
+ return - EINVAL ;
296
+
297
+ timeout = new_timeout ;
298
+ wdt_keepalive ();
299
+ /* Fall through */
300
+ }
301
+ case WDIOC_GETTIMEOUT :
302
+ return put_user (timeout , p );
297
303
}
298
304
}
299
305
@@ -303,7 +309,7 @@ static const struct file_operations wdt_fops = {
303
309
.write = fop_write ,
304
310
.open = fop_open ,
305
311
.release = fop_close ,
306
- .ioctl = fop_ioctl ,
312
+ .unlocked_ioctl = fop_ioctl ,
307
313
};
308
314
309
315
static struct miscdevice wdt_miscdev = {
@@ -319,7 +325,7 @@ static struct miscdevice wdt_miscdev = {
319
325
static int wdt_notify_sys (struct notifier_block * this , unsigned long code ,
320
326
void * unused )
321
327
{
322
- if (code == SYS_DOWN || code == SYS_HALT )
328
+ if (code == SYS_DOWN || code == SYS_HALT )
323
329
wdt_turnoff ();
324
330
return NOTIFY_DONE ;
325
331
}
@@ -329,8 +335,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
329
335
* turn the timebomb registers off.
330
336
*/
331
337
332
- static struct notifier_block wdt_notifier =
333
- {
338
+ static struct notifier_block wdt_notifier = {
334
339
.notifier_call = wdt_notify_sys ,
335
340
};
336
341
@@ -342,64 +347,62 @@ static void __exit w83877f_wdt_unload(void)
342
347
misc_deregister (& wdt_miscdev );
343
348
344
349
unregister_reboot_notifier (& wdt_notifier );
345
- release_region (WDT_PING ,1 );
346
- release_region (ENABLE_W83877F_PORT ,2 );
350
+ release_region (WDT_PING , 1 );
351
+ release_region (ENABLE_W83877F_PORT , 2 );
347
352
}
348
353
349
354
static int __init w83877f_wdt_init (void )
350
355
{
351
356
int rc = - EBUSY ;
352
357
353
- if (timeout < 1 || timeout > 3600 ) /* arbitrary upper limit */
354
- {
358
+ if (timeout < 1 || timeout > 3600 ) { /* arbitrary upper limit */
355
359
timeout = WATCHDOG_TIMEOUT ;
356
- printk (KERN_INFO PFX "timeout value must be 1<=x<=3600, using %d\n" ,
357
- timeout );
360
+ printk (KERN_INFO PFX
361
+ "timeout value must be 1 <= x <= 3600, using %d\n" ,
362
+ timeout );
358
363
}
359
364
360
- if (!request_region (ENABLE_W83877F_PORT , 2 , "W83877F WDT" ))
361
- {
365
+ if (!request_region (ENABLE_W83877F_PORT , 2 , "W83877F WDT" )) {
362
366
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n" ,
363
367
ENABLE_W83877F_PORT );
364
368
rc = - EIO ;
365
369
goto err_out ;
366
370
}
367
371
368
- if (!request_region (WDT_PING , 1 , "W8387FF WDT" ))
369
- {
372
+ if (!request_region (WDT_PING , 1 , "W8387FF WDT" )) {
370
373
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n" ,
371
374
WDT_PING );
372
375
rc = - EIO ;
373
376
goto err_out_region1 ;
374
377
}
375
378
376
379
rc = register_reboot_notifier (& wdt_notifier );
377
- if (rc )
378
- {
379
- printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n" ,
380
- rc );
380
+ if (rc ) {
381
+ printk (KERN_ERR PFX
382
+ "cannot register reboot notifier (err=%d)\n" , rc );
381
383
goto err_out_region2 ;
382
384
}
383
385
384
386
rc = misc_register (& wdt_miscdev );
385
- if (rc )
386
- {
387
- printk ( KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n" ,
388
- wdt_miscdev .minor , rc );
387
+ if (rc ) {
388
+ printk ( KERN_ERR PFX
389
+ "cannot register miscdev on minor=%d (err=%d)\n" ,
390
+ wdt_miscdev .minor , rc );
389
391
goto err_out_reboot ;
390
392
}
391
393
392
- printk (KERN_INFO PFX "WDT driver for W83877F initialised. timeout=%d sec (nowayout=%d)\n" ,
394
+ printk (KERN_INFO PFX
395
+ "WDT driver for W83877F initialised. timeout=%d sec (nowayout=%d)\n" ,
393
396
timeout , nowayout );
394
397
395
398
return 0 ;
396
399
397
400
err_out_reboot :
398
401
unregister_reboot_notifier (& wdt_notifier );
399
402
err_out_region2 :
400
- release_region (WDT_PING ,1 );
403
+ release_region (WDT_PING , 1 );
401
404
err_out_region1 :
402
- release_region (ENABLE_W83877F_PORT ,2 );
405
+ release_region (ENABLE_W83877F_PORT , 2 );
403
406
err_out :
404
407
return rc ;
405
408
}
0 commit comments