Skip to content

Commit 46a3949

Browse files
Alan CoxWim Van Sebroeck
authored andcommitted
[WATCHDOG 49/57] w83627hf: coding style, clean up 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 8dc244f commit 46a3949

File tree

1 file changed

+83
-92
lines changed

1 file changed

+83
-92
lines changed

drivers/watchdog/w83627hf_wdt.c

Lines changed: 83 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
#include <linux/reboot.h>
3838
#include <linux/init.h>
3939
#include <linux/spinlock.h>
40+
#include <linux/io.h>
41+
#include <linux/uaccess.h>
4042

41-
#include <asm/io.h>
42-
#include <asm/uaccess.h>
4343
#include <asm/system.h>
4444

4545
#define WATCHDOG_NAME "w83627hf/thf/hg WDT"
@@ -57,22 +57,26 @@ MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
5757

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

6264
static int nowayout = WATCHDOG_NOWAYOUT;
6365
module_param(nowayout, int, 0);
64-
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
66+
MODULE_PARM_DESC(nowayout,
67+
"Watchdog cannot be stopped once started (default="
68+
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
6569

6670
/*
6771
* Kernel methods.
6872
*/
6973

7074
#define WDT_EFER (wdt_io+0) /* Extended Function Enable Registers */
71-
#define WDT_EFIR (wdt_io+0) /* Extended Function Index Register (same as EFER) */
75+
#define WDT_EFIR (wdt_io+0) /* Extended Function Index Register
76+
(same as EFER) */
7277
#define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */
7378

74-
static void
75-
w83627hf_select_wd_register(void)
79+
static void w83627hf_select_wd_register(void)
7680
{
7781
unsigned char c;
7882
outb_p(0x87, WDT_EFER); /* Enter extended function mode */
@@ -93,43 +97,45 @@ w83627hf_select_wd_register(void)
9397
outb_p(0x01, WDT_EFDR); /* set bit 0 to activate GPIO2 */
9498
}
9599

96-
static void
97-
w83627hf_unselect_wd_register(void)
100+
static void w83627hf_unselect_wd_register(void)
98101
{
99102
outb_p(0xAA, WDT_EFER); /* Leave extended function mode */
100103
}
101104

102105
/* tyan motherboards seem to set F5 to 0x4C ?
103106
* So explicitly init to appropriate value. */
104-
static void
105-
w83627hf_init(void)
107+
108+
static void w83627hf_init(void)
106109
{
107110
unsigned char t;
108111

109112
w83627hf_select_wd_register();
110113

111114
outb_p(0xF6, WDT_EFER); /* Select CRF6 */
112-
t=inb_p(WDT_EFDR); /* read CRF6 */
115+
t = inb_p(WDT_EFDR); /* read CRF6 */
113116
if (t != 0) {
114-
printk (KERN_INFO PFX "Watchdog already running. Resetting timeout to %d sec\n", timeout);
117+
printk(KERN_INFO PFX
118+
"Watchdog already running. Resetting timeout to %d sec\n",
119+
timeout);
115120
outb_p(timeout, WDT_EFDR); /* Write back to CRF6 */
116121
}
117122

118123
outb_p(0xF5, WDT_EFER); /* Select CRF5 */
119-
t=inb_p(WDT_EFDR); /* read CRF5 */
120-
t&=~0x0C; /* set second mode & disable keyboard turning off watchdog */
124+
t = inb_p(WDT_EFDR); /* read CRF5 */
125+
t &= ~0x0C; /* set second mode & disable keyboard
126+
turning off watchdog */
121127
outb_p(t, WDT_EFDR); /* Write back to CRF5 */
122128

123129
outb_p(0xF7, WDT_EFER); /* Select CRF7 */
124-
t=inb_p(WDT_EFDR); /* read CRF7 */
125-
t&=~0xC0; /* disable keyboard & mouse turning off watchdog */
130+
t = inb_p(WDT_EFDR); /* read CRF7 */
131+
t &= ~0xC0; /* disable keyboard & mouse turning off
132+
watchdog */
126133
outb_p(t, WDT_EFDR); /* Write back to CRF7 */
127134

128135
w83627hf_unselect_wd_register();
129136
}
130137

131-
static void
132-
wdt_ctrl(int timeout)
138+
static void wdt_ctrl(int timeout)
133139
{
134140
spin_lock(&io_lock);
135141

@@ -143,32 +149,28 @@ wdt_ctrl(int timeout)
143149
spin_unlock(&io_lock);
144150
}
145151

146-
static int
147-
wdt_ping(void)
152+
static int wdt_ping(void)
148153
{
149154
wdt_ctrl(timeout);
150155
return 0;
151156
}
152157

153-
static int
154-
wdt_disable(void)
158+
static int wdt_disable(void)
155159
{
156160
wdt_ctrl(0);
157161
return 0;
158162
}
159163

160-
static int
161-
wdt_set_heartbeat(int t)
164+
static int wdt_set_heartbeat(int t)
162165
{
163-
if ((t < 1) || (t > 255))
166+
if (t < 1 || t > 255)
164167
return -EINVAL;
165-
166168
timeout = t;
167169
return 0;
168170
}
169171

170-
static ssize_t
171-
wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
172+
static ssize_t wdt_write(struct file *file, const char __user *buf,
173+
size_t count, loff_t *ppos)
172174
{
173175
if (count) {
174176
if (!nowayout) {
@@ -189,72 +191,61 @@ wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
189191
return count;
190192
}
191193

192-
static int
193-
wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
194-
unsigned long arg)
194+
static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
195195
{
196196
void __user *argp = (void __user *)arg;
197197
int __user *p = argp;
198198
int new_timeout;
199199
static struct watchdog_info ident = {
200-
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
200+
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
201+
WDIOF_MAGICCLOSE,
201202
.firmware_version = 1,
202203
.identity = "W83627HF WDT",
203204
};
204205

205206
switch (cmd) {
206207
case WDIOC_GETSUPPORT:
207-
if (copy_to_user(argp, &ident, sizeof(ident)))
208-
return -EFAULT;
209-
break;
210-
208+
if (copy_to_user(argp, &ident, sizeof(ident)))
209+
return -EFAULT;
210+
break;
211211
case WDIOC_GETSTATUS:
212212
case WDIOC_GETBOOTSTATUS:
213-
return put_user(0, p);
214-
213+
return put_user(0, p);
215214
case WDIOC_KEEPALIVE:
216-
wdt_ping();
217-
break;
218-
215+
wdt_ping();
216+
break;
219217
case WDIOC_SETTIMEOUT:
220-
if (get_user(new_timeout, p))
221-
return -EFAULT;
222-
if (wdt_set_heartbeat(new_timeout))
223-
return -EINVAL;
224-
wdt_ping();
225-
/* Fall */
226-
218+
if (get_user(new_timeout, p))
219+
return -EFAULT;
220+
if (wdt_set_heartbeat(new_timeout))
221+
return -EINVAL;
222+
wdt_ping();
223+
/* Fall */
227224
case WDIOC_GETTIMEOUT:
228-
return put_user(timeout, p);
229-
225+
return put_user(timeout, p);
230226
case WDIOC_SETOPTIONS:
231227
{
232-
int options, retval = -EINVAL;
233-
234-
if (get_user(options, p))
235-
return -EFAULT;
236-
237-
if (options & WDIOS_DISABLECARD) {
238-
wdt_disable();
239-
retval = 0;
240-
}
241-
242-
if (options & WDIOS_ENABLECARD) {
243-
wdt_ping();
244-
retval = 0;
245-
}
228+
int options, retval = -EINVAL;
246229

247-
return retval;
230+
if (get_user(options, p))
231+
return -EFAULT;
232+
if (options & WDIOS_DISABLECARD) {
233+
wdt_disable();
234+
retval = 0;
235+
}
236+
if (options & WDIOS_ENABLECARD) {
237+
wdt_ping();
238+
retval = 0;
239+
}
240+
return retval;
248241
}
249-
250242
default:
251-
return -ENOTTY;
243+
return -ENOTTY;
252244
}
253245
return 0;
254246
}
255247

256-
static int
257-
wdt_open(struct inode *inode, struct file *file)
248+
static int wdt_open(struct inode *inode, struct file *file)
258249
{
259250
if (test_and_set_bit(0, &wdt_is_open))
260251
return -EBUSY;
@@ -266,13 +257,13 @@ wdt_open(struct inode *inode, struct file *file)
266257
return nonseekable_open(inode, file);
267258
}
268259

269-
static int
270-
wdt_close(struct inode *inode, struct file *file)
260+
static int wdt_close(struct inode *inode, struct file *file)
271261
{
272-
if (expect_close == 42) {
262+
if (expect_close == 42)
273263
wdt_disable();
274-
} else {
275-
printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
264+
else {
265+
printk(KERN_CRIT PFX
266+
"Unexpected close, not stopping watchdog!\n");
276267
wdt_ping();
277268
}
278269
expect_close = 0;
@@ -284,8 +275,7 @@ wdt_close(struct inode *inode, struct file *file)
284275
* Notifier for system down
285276
*/
286277

287-
static int
288-
wdt_notify_sys(struct notifier_block *this, unsigned long code,
278+
static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
289279
void *unused)
290280
{
291281
if (code == SYS_DOWN || code == SYS_HALT) {
@@ -303,7 +293,7 @@ static const struct file_operations wdt_fops = {
303293
.owner = THIS_MODULE,
304294
.llseek = no_llseek,
305295
.write = wdt_write,
306-
.ioctl = wdt_ioctl,
296+
.unlocked_ioctl = wdt_ioctl,
307297
.open = wdt_open,
308298
.release = wdt_close,
309299
};
@@ -323,21 +313,21 @@ static struct notifier_block wdt_notifier = {
323313
.notifier_call = wdt_notify_sys,
324314
};
325315

326-
static int __init
327-
wdt_init(void)
316+
static int __init wdt_init(void)
328317
{
329318
int ret;
330319

331320
printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF/THF/HG Super I/O chip initialising.\n");
332321

333322
if (wdt_set_heartbeat(timeout)) {
334323
wdt_set_heartbeat(WATCHDOG_TIMEOUT);
335-
printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n",
336-
WATCHDOG_TIMEOUT);
324+
printk(KERN_INFO PFX
325+
"timeout value must be 1 <= timeout <= 255, using %d\n",
326+
WATCHDOG_TIMEOUT);
337327
}
338328

339329
if (!request_region(wdt_io, 1, WATCHDOG_NAME)) {
340-
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
330+
printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
341331
wdt_io);
342332
ret = -EIO;
343333
goto out;
@@ -347,20 +337,22 @@ wdt_init(void)
347337

348338
ret = register_reboot_notifier(&wdt_notifier);
349339
if (ret != 0) {
350-
printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
351-
ret);
340+
printk(KERN_ERR PFX
341+
"cannot register reboot notifier (err=%d)\n", ret);
352342
goto unreg_regions;
353343
}
354344

355345
ret = misc_register(&wdt_miscdev);
356346
if (ret != 0) {
357-
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
358-
WATCHDOG_MINOR, ret);
347+
printk(KERN_ERR PFX
348+
"cannot register miscdev on minor=%d (err=%d)\n",
349+
WATCHDOG_MINOR, ret);
359350
goto unreg_reboot;
360351
}
361352

362-
printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
363-
timeout, nowayout);
353+
printk(KERN_INFO PFX
354+
"initialized. timeout=%d sec (nowayout=%d)\n",
355+
timeout, nowayout);
364356

365357
out:
366358
return ret;
@@ -371,12 +363,11 @@ wdt_init(void)
371363
goto out;
372364
}
373365

374-
static void __exit
375-
wdt_exit(void)
366+
static void __exit wdt_exit(void)
376367
{
377368
misc_deregister(&wdt_miscdev);
378369
unregister_reboot_notifier(&wdt_notifier);
379-
release_region(wdt_io,1);
370+
release_region(wdt_io, 1);
380371
}
381372

382373
module_init(wdt_init);

0 commit comments

Comments
 (0)