aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-05-19 09:04:46 -0400
committerWim Van Sebroeck <wim@iguana.be>2008-05-27 11:22:12 -0400
commit94da1e2eff319994eefc7d04de7c911f64146e88 (patch)
treed99ae11559e8f37d1d1bfdd326eeda72203e9763 /drivers/watchdog
parente490517a039a99d692cb3a5561941b0a5f576172 (diff)
[WATCHDOG 01/57] Clean acquirewdt and check for BKL dependancies
This brings the file into line with coding style. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/acquirewdt.c119
1 files changed, 58 insertions, 61 deletions
diff --git a/drivers/watchdog/acquirewdt.c b/drivers/watchdog/acquirewdt.c
index 85269c365a10..269ada2f1fc3 100644
--- a/drivers/watchdog/acquirewdt.c
+++ b/drivers/watchdog/acquirewdt.c
@@ -58,39 +58,46 @@
58#include <linux/types.h> /* For standard types (like size_t) */ 58#include <linux/types.h> /* For standard types (like size_t) */
59#include <linux/errno.h> /* For the -ENODEV/... values */ 59#include <linux/errno.h> /* For the -ENODEV/... values */
60#include <linux/kernel.h> /* For printk/panic/... */ 60#include <linux/kernel.h> /* For printk/panic/... */
61#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ 61#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
62 (WATCHDOG_MINOR) */
62#include <linux/watchdog.h> /* For the watchdog specific items */ 63#include <linux/watchdog.h> /* For the watchdog specific items */
63#include <linux/fs.h> /* For file operations */ 64#include <linux/fs.h> /* For file operations */
64#include <linux/ioport.h> /* For io-port access */ 65#include <linux/ioport.h> /* For io-port access */
65#include <linux/platform_device.h> /* For platform_driver framework */ 66#include <linux/platform_device.h> /* For platform_driver framework */
66#include <linux/init.h> /* For __init/__exit/... */ 67#include <linux/init.h> /* For __init/__exit/... */
67 68
68#include <asm/uaccess.h> /* For copy_to_user/put_user/... */ 69#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
69#include <asm/io.h> /* For inb/outb/... */ 70#include <linux/io.h> /* For inb/outb/... */
70 71
71/* Module information */ 72/* Module information */
72#define DRV_NAME "acquirewdt" 73#define DRV_NAME "acquirewdt"
73#define PFX DRV_NAME ": " 74#define PFX DRV_NAME ": "
74#define WATCHDOG_NAME "Acquire WDT" 75#define WATCHDOG_NAME "Acquire WDT"
75#define WATCHDOG_HEARTBEAT 0 /* There is no way to see what the correct time-out period is */ 76/* There is no way to see what the correct time-out period is */
77#define WATCHDOG_HEARTBEAT 0
76 78
77/* internal variables */ 79/* internal variables */
78static struct platform_device *acq_platform_device; /* the watchdog platform device */ 80/* the watchdog platform device */
81static struct platform_device *acq_platform_device;
79static unsigned long acq_is_open; 82static unsigned long acq_is_open;
80static char expect_close; 83static char expect_close;
81 84
82/* module parameters */ 85/* module parameters */
83static int wdt_stop = 0x43; /* You must set this - there is no sane way to probe for this board. */ 86/* You must set this - there is no sane way to probe for this board. */
87static int wdt_stop = 0x43;
84module_param(wdt_stop, int, 0); 88module_param(wdt_stop, int, 0);
85MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)"); 89MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)");
86 90
87static int wdt_start = 0x443; /* You must set this - there is no sane way to probe for this board. */ 91/* You must set this - there is no sane way to probe for this board. */
92static int wdt_start = 0x443;
88module_param(wdt_start, int, 0); 93module_param(wdt_start, int, 0);
89MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)"); 94MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");
90 95
91static int nowayout = WATCHDOG_NOWAYOUT; 96static int nowayout = WATCHDOG_NOWAYOUT;
92module_param(nowayout, int, 0); 97module_param(nowayout, int, 0);
93MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 98MODULE_PARM_DESC(nowayout,
99 "Watchdog cannot be stopped once started (default="
100 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
94 101
95/* 102/*
96 * Watchdog Operations 103 * Watchdog Operations
@@ -112,18 +119,18 @@ static void acq_stop(void)
112 * /dev/watchdog handling 119 * /dev/watchdog handling
113 */ 120 */
114 121
115static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 122static ssize_t acq_write(struct file *file, const char __user *buf,
123 size_t count, loff_t *ppos)
116{ 124{
117 /* See if we got the magic character 'V' and reload the timer */ 125 /* See if we got the magic character 'V' and reload the timer */
118 if(count) { 126 if (count) {
119 if (!nowayout) { 127 if (!nowayout) {
120 size_t i; 128 size_t i;
121
122 /* note: just in case someone wrote the magic character 129 /* note: just in case someone wrote the magic character
123 * five months ago... */ 130 * five months ago... */
124 expect_close = 0; 131 expect_close = 0;
125 132 /* scan to see whether or not we got the
126 /* scan to see whether or not we got the magic character */ 133 magic character */
127 for (i = 0; i != count; i++) { 134 for (i = 0; i != count; i++) {
128 char c; 135 char c;
129 if (get_user(c, buf + i)) 136 if (get_user(c, buf + i))
@@ -132,64 +139,55 @@ static ssize_t acq_write(struct file *file, const char __user *buf, size_t count
132 expect_close = 42; 139 expect_close = 42;
133 } 140 }
134 } 141 }
135 142 /* Well, anyhow someone wrote to us, we should
136 /* Well, anyhow someone wrote to us, we should return that favour */ 143 return that favour */
137 acq_keepalive(); 144 acq_keepalive();
138 } 145 }
139 return count; 146 return count;
140} 147}
141 148
142static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 149static long acq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
143 unsigned long arg)
144{ 150{
145 int options, retval = -EINVAL; 151 int options, retval = -EINVAL;
146 void __user *argp = (void __user *)arg; 152 void __user *argp = (void __user *)arg;
147 int __user *p = argp; 153 int __user *p = argp;
148 static struct watchdog_info ident = 154 static struct watchdog_info ident = {
149 {
150 .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 155 .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
151 .firmware_version = 1, 156 .firmware_version = 1,
152 .identity = WATCHDOG_NAME, 157 .identity = WATCHDOG_NAME,
153 }; 158 };
154 159
155 switch(cmd) 160 switch (cmd) {
156 {
157 case WDIOC_GETSUPPORT: 161 case WDIOC_GETSUPPORT:
158 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; 162 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
159 163
160 case WDIOC_GETSTATUS: 164 case WDIOC_GETSTATUS:
161 case WDIOC_GETBOOTSTATUS: 165 case WDIOC_GETBOOTSTATUS:
162 return put_user(0, p); 166 return put_user(0, p);
163 167
164 case WDIOC_KEEPALIVE: 168 case WDIOC_KEEPALIVE:
165 acq_keepalive(); 169 acq_keepalive();
166 return 0; 170 return 0;
167 171
168 case WDIOC_GETTIMEOUT: 172 case WDIOC_GETTIMEOUT:
169 return put_user(WATCHDOG_HEARTBEAT, p); 173 return put_user(WATCHDOG_HEARTBEAT, p);
170 174
171 case WDIOC_SETOPTIONS: 175 case WDIOC_SETOPTIONS:
172 { 176 {
173 if (get_user(options, p)) 177 if (get_user(options, p))
174 return -EFAULT; 178 return -EFAULT;
175 179 if (options & WDIOS_DISABLECARD) {
176 if (options & WDIOS_DISABLECARD) 180 acq_stop();
177 { 181 retval = 0;
178 acq_stop(); 182 }
179 retval = 0; 183 if (options & WDIOS_ENABLECARD) {
180 } 184 acq_keepalive();
181 185 retval = 0;
182 if (options & WDIOS_ENABLECARD) 186 }
183 { 187 return retval;
184 acq_keepalive();
185 retval = 0;
186 }
187
188 return retval;
189 } 188 }
190
191 default: 189 default:
192 return -ENOTTY; 190 return -ENOTTY;
193 } 191 }
194} 192}
195 193
@@ -211,7 +209,8 @@ static int acq_close(struct inode *inode, struct file *file)
211 if (expect_close == 42) { 209 if (expect_close == 42) {
212 acq_stop(); 210 acq_stop();
213 } else { 211 } else {
214 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 212 printk(KERN_CRIT PFX
213 "Unexpected close, not stopping watchdog!\n");
215 acq_keepalive(); 214 acq_keepalive();
216 } 215 }
217 clear_bit(0, &acq_is_open); 216 clear_bit(0, &acq_is_open);
@@ -227,7 +226,7 @@ static const struct file_operations acq_fops = {
227 .owner = THIS_MODULE, 226 .owner = THIS_MODULE,
228 .llseek = no_llseek, 227 .llseek = no_llseek,
229 .write = acq_write, 228 .write = acq_write,
230 .ioctl = acq_ioctl, 229 .unlocked_ioctl = acq_ioctl,
231 .open = acq_open, 230 .open = acq_open,
232 .release = acq_close, 231 .release = acq_close,
233}; 232};
@@ -248,32 +247,29 @@ static int __devinit acq_probe(struct platform_device *dev)
248 247
249 if (wdt_stop != wdt_start) { 248 if (wdt_stop != wdt_start) {
250 if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { 249 if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
251 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", 250 printk(KERN_ERR PFX
252 wdt_stop); 251 "I/O address 0x%04x already in use\n", wdt_stop);
253 ret = -EIO; 252 ret = -EIO;
254 goto out; 253 goto out;
255 } 254 }
256 } 255 }
257 256
258 if (!request_region(wdt_start, 1, WATCHDOG_NAME)) { 257 if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
259 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", 258 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
260 wdt_start); 259 wdt_start);
261 ret = -EIO; 260 ret = -EIO;
262 goto unreg_stop; 261 goto unreg_stop;
263 } 262 }
264
265 ret = misc_register(&acq_miscdev); 263 ret = misc_register(&acq_miscdev);
266 if (ret != 0) { 264 if (ret != 0) {
267 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 265 printk(KERN_ERR PFX
268 WATCHDOG_MINOR, ret); 266 "cannot register miscdev on minor=%d (err=%d)\n",
267 WATCHDOG_MINOR, ret);
269 goto unreg_regions; 268 goto unreg_regions;
270 } 269 }
271 270 printk(KERN_INFO PFX "initialized. (nowayout=%d)\n", nowayout);
272 printk (KERN_INFO PFX "initialized. (nowayout=%d)\n",
273 nowayout);
274 271
275 return 0; 272 return 0;
276
277unreg_regions: 273unreg_regions:
278 release_region(wdt_start, 1); 274 release_region(wdt_start, 1);
279unreg_stop: 275unreg_stop:
@@ -286,9 +282,9 @@ out:
286static int __devexit acq_remove(struct platform_device *dev) 282static int __devexit acq_remove(struct platform_device *dev)
287{ 283{
288 misc_deregister(&acq_miscdev); 284 misc_deregister(&acq_miscdev);
289 release_region(wdt_start,1); 285 release_region(wdt_start, 1);
290 if(wdt_stop != wdt_start) 286 if (wdt_stop != wdt_start)
291 release_region(wdt_stop,1); 287 release_region(wdt_stop, 1);
292 288
293 return 0; 289 return 0;
294} 290}
@@ -313,18 +309,19 @@ static int __init acq_init(void)
313{ 309{
314 int err; 310 int err;
315 311
316 printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n"); 312 printk(KERN_INFO
313 "WDT driver for Acquire single board computer initialising.\n");
317 314
318 err = platform_driver_register(&acquirewdt_driver); 315 err = platform_driver_register(&acquirewdt_driver);
319 if (err) 316 if (err)
320 return err; 317 return err;
321 318
322 acq_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); 319 acq_platform_device = platform_device_register_simple(DRV_NAME,
320 -1, NULL, 0);
323 if (IS_ERR(acq_platform_device)) { 321 if (IS_ERR(acq_platform_device)) {
324 err = PTR_ERR(acq_platform_device); 322 err = PTR_ERR(acq_platform_device);
325 goto unreg_platform_driver; 323 goto unreg_platform_driver;
326 } 324 }
327
328 return 0; 325 return 0;
329 326
330unreg_platform_driver: 327unreg_platform_driver: