Skip to content

Commit c1c8dd3

Browse files
Alan CoxWim Van Sebroeck
authored andcommitted
[WATCHDOG 50/57] w83697hf_wdt: cleanup, coding style and 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 46a3949 commit c1c8dd3

File tree

1 file changed

+73
-75
lines changed

1 file changed

+73
-75
lines changed

drivers/watchdog/w83697hf_wdt.c

Lines changed: 73 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#include <linux/reboot.h>
3737
#include <linux/init.h>
3838
#include <linux/spinlock.h>
39+
#include <linux/io.h>
40+
#include <linux/uaccess.h>
3941

40-
#include <asm/io.h>
41-
#include <asm/uaccess.h>
4242
#include <asm/system.h>
4343

4444
#define WATCHDOG_NAME "w83697hf/hg WDT"
@@ -53,37 +53,43 @@ static DEFINE_SPINLOCK(io_lock);
5353
/* You must set this - there is no sane way to probe for this board. */
5454
static int wdt_io = 0x2e;
5555
module_param(wdt_io, int, 0);
56-
MODULE_PARM_DESC(wdt_io, "w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
56+
MODULE_PARM_DESC(wdt_io,
57+
"w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
5758

5859
static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
5960
module_param(timeout, int, 0);
60-
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255 (default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
61+
MODULE_PARM_DESC(timeout,
62+
"Watchdog timeout in seconds. 1<= timeout <=255 (default="
63+
__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
6164

6265
static int nowayout = WATCHDOG_NOWAYOUT;
6366
module_param(nowayout, int, 0);
64-
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
67+
MODULE_PARM_DESC(nowayout,
68+
"Watchdog cannot be stopped once started (default="
69+
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
6570

6671
static int early_disable = WATCHDOG_EARLY_DISABLE;
6772
module_param(early_disable, int, 0);
68-
MODULE_PARM_DESC(early_disable, "Watchdog gets disabled at boot time (default=" __MODULE_STRING(WATCHDOG_EARLY_DISABLE) ")");
73+
MODULE_PARM_DESC(early_disable,
74+
"Watchdog gets disabled at boot time (default="
75+
__MODULE_STRING(WATCHDOG_EARLY_DISABLE) ")");
6976

7077
/*
7178
* Kernel methods.
7279
*/
7380

74-
#define W83697HF_EFER (wdt_io+0) /* Extended Function Enable Register */
75-
#define W83697HF_EFIR (wdt_io+0) /* Extended Function Index Register (same as EFER) */
76-
#define W83697HF_EFDR (wdt_io+1) /* Extended Function Data Register */
81+
#define W83697HF_EFER (wdt_io + 0) /* Extended Function Enable Register */
82+
#define W83697HF_EFIR (wdt_io + 0) /* Extended Function Index Register
83+
(same as EFER) */
84+
#define W83697HF_EFDR (wdt_io + 1) /* Extended Function Data Register */
7785

78-
static inline void
79-
w83697hf_unlock(void)
86+
static inline void w83697hf_unlock(void)
8087
{
8188
outb_p(0x87, W83697HF_EFER); /* Enter extended function mode */
8289
outb_p(0x87, W83697HF_EFER); /* Again according to manual */
8390
}
8491

85-
static inline void
86-
w83697hf_lock(void)
92+
static inline void w83697hf_lock(void)
8793
{
8894
outb_p(0xAA, W83697HF_EFER); /* Leave extended function mode */
8995
}
@@ -93,41 +99,36 @@ w83697hf_lock(void)
9399
* w83697hf_write_timeout() must be called with the device unlocked.
94100
*/
95101

96-
static unsigned char
97-
w83697hf_get_reg(unsigned char reg)
102+
static unsigned char w83697hf_get_reg(unsigned char reg)
98103
{
99104
outb_p(reg, W83697HF_EFIR);
100105
return inb_p(W83697HF_EFDR);
101106
}
102107

103-
static void
104-
w83697hf_set_reg(unsigned char reg, unsigned char data)
108+
static void w83697hf_set_reg(unsigned char reg, unsigned char data)
105109
{
106110
outb_p(reg, W83697HF_EFIR);
107111
outb_p(data, W83697HF_EFDR);
108112
}
109113

110-
static void
111-
w83697hf_write_timeout(int timeout)
114+
static void w83697hf_write_timeout(int timeout)
112115
{
113-
w83697hf_set_reg(0xF4, timeout); /* Write Timeout counter to CRF4 */
116+
/* Write Timeout counter to CRF4 */
117+
w83697hf_set_reg(0xF4, timeout);
114118
}
115119

116-
static void
117-
w83697hf_select_wdt(void)
120+
static void w83697hf_select_wdt(void)
118121
{
119122
w83697hf_unlock();
120123
w83697hf_set_reg(0x07, 0x08); /* Switch to logic device 8 (GPIO2) */
121124
}
122125

123-
static inline void
124-
w83697hf_deselect_wdt(void)
126+
static inline void w83697hf_deselect_wdt(void)
125127
{
126128
w83697hf_lock();
127129
}
128130

129-
static void
130-
w83697hf_init(void)
131+
static void w83697hf_init(void)
131132
{
132133
unsigned char bbuf;
133134

@@ -136,7 +137,9 @@ w83697hf_init(void)
136137
bbuf = w83697hf_get_reg(0x29);
137138
bbuf &= ~0x60;
138139
bbuf |= 0x20;
139-
w83697hf_set_reg(0x29, bbuf); /* Set pin 119 to WDTO# mode (= CR29, WDT0) */
140+
141+
/* Set pin 119 to WDTO# mode (= CR29, WDT0) */
142+
w83697hf_set_reg(0x29, bbuf);
140143

141144
bbuf = w83697hf_get_reg(0xF3);
142145
bbuf &= ~0x04;
@@ -145,8 +148,7 @@ w83697hf_init(void)
145148
w83697hf_deselect_wdt();
146149
}
147150

148-
static void
149-
wdt_ping(void)
151+
static void wdt_ping(void)
150152
{
151153
spin_lock(&io_lock);
152154
w83697hf_select_wdt();
@@ -157,8 +159,7 @@ wdt_ping(void)
157159
spin_unlock(&io_lock);
158160
}
159161

160-
static void
161-
wdt_enable(void)
162+
static void wdt_enable(void)
162163
{
163164
spin_lock(&io_lock);
164165
w83697hf_select_wdt();
@@ -170,8 +171,7 @@ wdt_enable(void)
170171
spin_unlock(&io_lock);
171172
}
172173

173-
static void
174-
wdt_disable(void)
174+
static void wdt_disable(void)
175175
{
176176
spin_lock(&io_lock);
177177
w83697hf_select_wdt();
@@ -183,8 +183,7 @@ wdt_disable(void)
183183
spin_unlock(&io_lock);
184184
}
185185

186-
static unsigned char
187-
wdt_running(void)
186+
static unsigned char wdt_running(void)
188187
{
189188
unsigned char t;
190189

@@ -199,18 +198,17 @@ wdt_running(void)
199198
return t;
200199
}
201200

202-
static int
203-
wdt_set_heartbeat(int t)
201+
static int wdt_set_heartbeat(int t)
204202
{
205-
if ((t < 1) || (t > 255))
203+
if (t < 1 || t > 255)
206204
return -EINVAL;
207205

208206
timeout = t;
209207
return 0;
210208
}
211209

212-
static ssize_t
213-
wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
210+
static ssize_t wdt_write(struct file *file, const char __user *buf,
211+
size_t count, loff_t *ppos)
214212
{
215213
if (count) {
216214
if (!nowayout) {
@@ -231,15 +229,14 @@ wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
231229
return count;
232230
}
233231

234-
static int
235-
wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
236-
unsigned long arg)
232+
static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
237233
{
238234
void __user *argp = (void __user *)arg;
239235
int __user *p = argp;
240236
int new_timeout;
241-
static struct watchdog_info ident = {
242-
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
237+
static const struct watchdog_info ident = {
238+
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
239+
| WDIOF_MAGICCLOSE,
243240
.firmware_version = 1,
244241
.identity = "W83697HF WDT",
245242
};
@@ -295,8 +292,7 @@ wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
295292
return 0;
296293
}
297294

298-
static int
299-
wdt_open(struct inode *inode, struct file *file)
295+
static int wdt_open(struct inode *inode, struct file *file)
300296
{
301297
if (test_and_set_bit(0, &wdt_is_open))
302298
return -EBUSY;
@@ -308,13 +304,13 @@ wdt_open(struct inode *inode, struct file *file)
308304
return nonseekable_open(inode, file);
309305
}
310306

311-
static int
312-
wdt_close(struct inode *inode, struct file *file)
307+
static int wdt_close(struct inode *inode, struct file *file)
313308
{
314-
if (expect_close == 42) {
309+
if (expect_close == 42)
315310
wdt_disable();
316-
} else {
317-
printk (KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
311+
else {
312+
printk(KERN_CRIT PFX
313+
"Unexpected close, not stopping watchdog!\n");
318314
wdt_ping();
319315
}
320316
expect_close = 0;
@@ -326,8 +322,7 @@ wdt_close(struct inode *inode, struct file *file)
326322
* Notifier for system down
327323
*/
328324

329-
static int
330-
wdt_notify_sys(struct notifier_block *this, unsigned long code,
325+
static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
331326
void *unused)
332327
{
333328
if (code == SYS_DOWN || code == SYS_HALT) {
@@ -345,7 +340,7 @@ static const struct file_operations wdt_fops = {
345340
.owner = THIS_MODULE,
346341
.llseek = no_llseek,
347342
.write = wdt_write,
348-
.ioctl = wdt_ioctl,
343+
.unlocked_ioctl = wdt_ioctl,
349344
.open = wdt_open,
350345
.release = wdt_close,
351346
};
@@ -365,36 +360,38 @@ static struct notifier_block wdt_notifier = {
365360
.notifier_call = wdt_notify_sys,
366361
};
367362

368-
static int
369-
w83697hf_check_wdt(void)
363+
static int w83697hf_check_wdt(void)
370364
{
371365
if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
372-
printk (KERN_ERR PFX "I/O address 0x%x already in use\n", wdt_io);
366+
printk(KERN_ERR PFX
367+
"I/O address 0x%x already in use\n", wdt_io);
373368
return -EIO;
374369
}
375370

376-
printk (KERN_DEBUG PFX "Looking for watchdog at address 0x%x\n", wdt_io);
371+
printk(KERN_DEBUG PFX
372+
"Looking for watchdog at address 0x%x\n", wdt_io);
377373
w83697hf_unlock();
378374
if (w83697hf_get_reg(0x20) == 0x60) {
379-
printk (KERN_INFO PFX "watchdog found at address 0x%x\n", wdt_io);
375+
printk(KERN_INFO PFX
376+
"watchdog found at address 0x%x\n", wdt_io);
380377
w83697hf_lock();
381378
return 0;
382379
}
383-
w83697hf_lock(); /* Reprotect in case it was a compatible device */
380+
/* Reprotect in case it was a compatible device */
381+
w83697hf_lock();
384382

385-
printk (KERN_INFO PFX "watchdog not found at address 0x%x\n", wdt_io);
383+
printk(KERN_INFO PFX "watchdog not found at address 0x%x\n", wdt_io);
386384
release_region(wdt_io, 2);
387385
return -EIO;
388386
}
389387

390388
static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 };
391389

392-
static int __init
393-
wdt_init(void)
390+
static int __init wdt_init(void)
394391
{
395392
int ret, i, found = 0;
396393

397-
printk (KERN_INFO PFX "WDT driver for W83697HF/HG initializing\n");
394+
printk(KERN_INFO PFX "WDT driver for W83697HF/HG initializing\n");
398395

399396
if (wdt_io == 0) {
400397
/* we will autodetect the W83697HF/HG watchdog */
@@ -409,7 +406,7 @@ wdt_init(void)
409406
}
410407

411408
if (!found) {
412-
printk (KERN_ERR PFX "No W83697HF/HG could be found\n");
409+
printk(KERN_ERR PFX "No W83697HF/HG could be found\n");
413410
ret = -EIO;
414411
goto out;
415412
}
@@ -423,25 +420,27 @@ wdt_init(void)
423420

424421
if (wdt_set_heartbeat(timeout)) {
425422
wdt_set_heartbeat(WATCHDOG_TIMEOUT);
426-
printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n",
427-
WATCHDOG_TIMEOUT);
423+
printk(KERN_INFO PFX
424+
"timeout value must be 1 <= timeout <= 255, using %d\n",
425+
WATCHDOG_TIMEOUT);
428426
}
429427

430428
ret = register_reboot_notifier(&wdt_notifier);
431429
if (ret != 0) {
432-
printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
433-
ret);
430+
printk(KERN_ERR PFX
431+
"cannot register reboot notifier (err=%d)\n", ret);
434432
goto unreg_regions;
435433
}
436434

437435
ret = misc_register(&wdt_miscdev);
438436
if (ret != 0) {
439-
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
440-
WATCHDOG_MINOR, ret);
437+
printk(KERN_ERR PFX
438+
"cannot register miscdev on minor=%d (err=%d)\n",
439+
WATCHDOG_MINOR, ret);
441440
goto unreg_reboot;
442441
}
443442

444-
printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
443+
printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
445444
timeout, nowayout);
446445

447446
out:
@@ -453,8 +452,7 @@ wdt_init(void)
453452
goto out;
454453
}
455454

456-
static void __exit
457-
wdt_exit(void)
455+
static void __exit wdt_exit(void)
458456
{
459457
misc_deregister(&wdt_miscdev);
460458
unregister_reboot_notifier(&wdt_notifier);

0 commit comments

Comments
 (0)