Skip to content

Commit c1cfd1a

Browse files
Alan CoxWim Van Sebroeck
authored andcommitted
[WATCHDOG 51/57] w83877f_wdt: clean up code, coding style, switch to unlocked_ioctl
Review and switch to unlocked_ioctl Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
1 parent c1c8dd3 commit c1cfd1a

File tree

1 file changed

+101
-98
lines changed

1 file changed

+101
-98
lines changed

drivers/watchdog/w83877f_wdt.c

Lines changed: 101 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
* Added KERN_* tags to printks
2424
* add CONFIG_WATCHDOG_NOWAYOUT support
2525
* 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,
2830
* WDIOC_GETTIMEOUT, and WDIOC_SETOPTIONS ioctls
2931
* 09/8 - 2003 [wim@iguana.be] cleanup of trailing spaces
3032
* added extra printk's for startup problems
3133
* use module_param
32-
* made timeout (the emulated heartbeat) a module_param
34+
* made timeout (the emulated heartbeat) a
35+
* module_param
3336
* made the keepalive ping an internal subroutine
3437
*
3538
* This WDT driver is different from most other Linux WDT
@@ -51,8 +54,8 @@
5154
#include <linux/notifier.h>
5255
#include <linux/reboot.h>
5356
#include <linux/init.h>
54-
#include <asm/io.h>
55-
#include <asm/uaccess.h>
57+
#include <linux/io.h>
58+
#include <linux/uaccess.h>
5659
#include <asm/system.h>
5760

5861
#define OUR_NAME "w83877f_wdt"
@@ -80,14 +83,19 @@
8083
*/
8184

8285
#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;
8488
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) ")");
8692

8793

8894
static int nowayout = WATCHDOG_NOWAYOUT;
8995
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) ")");
9199

92100
static void wdt_timer_ping(unsigned long);
93101
static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0);
@@ -105,8 +113,7 @@ static void wdt_timer_ping(unsigned long data)
105113
/* If we got a heartbeat pulse within the WDT_US_INTERVAL
106114
* we agree to ping the WDT
107115
*/
108-
if(time_before(jiffies, next_heartbeat))
109-
{
116+
if (time_before(jiffies, next_heartbeat)) {
110117
/* Ping the WDT */
111118
spin_lock(&wdt_spinlock);
112119

@@ -118,9 +125,9 @@ static void wdt_timer_ping(unsigned long data)
118125

119126
spin_unlock(&wdt_spinlock);
120127

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");
124131
}
125132

126133
/*
@@ -181,22 +188,21 @@ static void wdt_keepalive(void)
181188
* /dev/watchdog handling
182189
*/
183190

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)
185193
{
186194
/* 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) {
191197
size_t ofs;
192198

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... */
195201
wdt_expect_close = 0;
196202

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++) {
200206
char c;
201207
if (get_user(c, buf + ofs))
202208
return -EFAULT;
@@ -211,89 +217,89 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou
211217
return count;
212218
}
213219

214-
static int fop_open(struct inode * inode, struct file * file)
220+
static int fop_open(struct inode *inode, struct file *file)
215221
{
216222
/* 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))
218224
return -EBUSY;
219225

220226
/* Good, fire up the show */
221227
wdt_startup();
222228
return nonseekable_open(inode, file);
223229
}
224230

225-
static int fop_close(struct inode * inode, struct file * file)
231+
static int fop_close(struct inode *inode, struct file *file)
226232
{
227-
if(wdt_expect_close == 42)
233+
if (wdt_expect_close == 42)
228234
wdt_turnoff();
229235
else {
230236
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");
232239
}
233240
clear_bit(0, &wdt_is_open);
234241
wdt_expect_close = 0;
235242
return 0;
236243
}
237244

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)
240246
{
241247
void __user *argp = (void __user *)arg;
242248
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,
246252
.firmware_version = 1,
247253
.identity = "W83877F",
248254
};
249255

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:
251268
{
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;
273270

274-
if(new_options & WDIOS_ENABLECARD) {
275-
wdt_startup();
276-
retval = 0;
277-
}
271+
if (get_user(new_options, p))
272+
return -EFAULT;
278273

279-
return retval;
274+
if (new_options & WDIOS_DISABLECARD) {
275+
wdt_turnoff();
276+
retval = 0;
280277
}
281-
case WDIOC_SETTIMEOUT:
282-
{
283-
int new_timeout;
284278

285-
if(get_user(new_timeout, p))
286-
return -EFAULT;
279+
if (new_options & WDIOS_ENABLECARD) {
280+
wdt_startup();
281+
retval = 0;
282+
}
287283

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;
290289

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);
297303
}
298304
}
299305

@@ -303,7 +309,7 @@ static const struct file_operations wdt_fops = {
303309
.write = fop_write,
304310
.open = fop_open,
305311
.release = fop_close,
306-
.ioctl = fop_ioctl,
312+
.unlocked_ioctl = fop_ioctl,
307313
};
308314

309315
static struct miscdevice wdt_miscdev = {
@@ -319,7 +325,7 @@ static struct miscdevice wdt_miscdev = {
319325
static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
320326
void *unused)
321327
{
322-
if(code==SYS_DOWN || code==SYS_HALT)
328+
if (code == SYS_DOWN || code == SYS_HALT)
323329
wdt_turnoff();
324330
return NOTIFY_DONE;
325331
}
@@ -329,8 +335,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
329335
* turn the timebomb registers off.
330336
*/
331337

332-
static struct notifier_block wdt_notifier=
333-
{
338+
static struct notifier_block wdt_notifier = {
334339
.notifier_call = wdt_notify_sys,
335340
};
336341

@@ -342,64 +347,62 @@ static void __exit w83877f_wdt_unload(void)
342347
misc_deregister(&wdt_miscdev);
343348

344349
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);
347352
}
348353

349354
static int __init w83877f_wdt_init(void)
350355
{
351356
int rc = -EBUSY;
352357

353-
if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */
354-
{
358+
if (timeout < 1 || timeout > 3600) { /* arbitrary upper limit */
355359
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);
358363
}
359364

360-
if (!request_region(ENABLE_W83877F_PORT, 2, "W83877F WDT"))
361-
{
365+
if (!request_region(ENABLE_W83877F_PORT, 2, "W83877F WDT")) {
362366
printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
363367
ENABLE_W83877F_PORT);
364368
rc = -EIO;
365369
goto err_out;
366370
}
367371

368-
if (!request_region(WDT_PING, 1, "W8387FF WDT"))
369-
{
372+
if (!request_region(WDT_PING, 1, "W8387FF WDT")) {
370373
printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
371374
WDT_PING);
372375
rc = -EIO;
373376
goto err_out_region1;
374377
}
375378

376379
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);
381383
goto err_out_region2;
382384
}
383385

384386
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);
389391
goto err_out_reboot;
390392
}
391393

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",
393396
timeout, nowayout);
394397

395398
return 0;
396399

397400
err_out_reboot:
398401
unregister_reboot_notifier(&wdt_notifier);
399402
err_out_region2:
400-
release_region(WDT_PING,1);
403+
release_region(WDT_PING, 1);
401404
err_out_region1:
402-
release_region(ENABLE_W83877F_PORT,2);
405+
release_region(ENABLE_W83877F_PORT, 2);
403406
err_out:
404407
return rc;
405408
}

0 commit comments

Comments
 (0)