aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/ib700wdt.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-05-19 09:05:52 -0400
committerWim Van Sebroeck <wim@iguana.be>2008-05-27 14:34:00 -0400
commit2e43ba73d4e2d34ddb9843e30480be3752514c16 (patch)
treeece08573f3bdd2707abe92dea8c9ac2aaad7b74e /drivers/watchdog/ib700wdt.c
parent6513e2a03887c6c9bd0b30593827a01ce3f7b542 (diff)
[WATCHDOG 12/57] ib700wdt: 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>
Diffstat (limited to 'drivers/watchdog/ib700wdt.c')
-rw-r--r--drivers/watchdog/ib700wdt.c103
1 files changed, 52 insertions, 51 deletions
diff --git a/drivers/watchdog/ib700wdt.c b/drivers/watchdog/ib700wdt.c
index 4b89f401691a..805a54b02aa1 100644
--- a/drivers/watchdog/ib700wdt.c
+++ b/drivers/watchdog/ib700wdt.c
@@ -42,8 +42,8 @@
42#include <linux/moduleparam.h> 42#include <linux/moduleparam.h>
43#include <linux/platform_device.h> 43#include <linux/platform_device.h>
44 44
45#include <asm/io.h> 45#include <linux/io.h>
46#include <asm/uaccess.h> 46#include <linux/uaccess.h>
47#include <asm/system.h> 47#include <asm/system.h>
48 48
49static struct platform_device *ibwdt_platform_device; 49static struct platform_device *ibwdt_platform_device;
@@ -120,7 +120,9 @@ static int wd_margin = WD_TIMO;
120 120
121static int nowayout = WATCHDOG_NOWAYOUT; 121static int nowayout = WATCHDOG_NOWAYOUT;
122module_param(nowayout, int, 0); 122module_param(nowayout, int, 0);
123MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 123MODULE_PARM_DESC(nowayout,
124 "Watchdog cannot be stopped once started (default="
125 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
124 126
125 127
126/* 128/*
@@ -165,8 +167,8 @@ ibwdt_set_heartbeat(int t)
165 * /dev/watchdog handling 167 * /dev/watchdog handling
166 */ 168 */
167 169
168static ssize_t 170static ssize_t ibwdt_write(struct file *file, const char __user *buf,
169ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 171 size_t count, loff_t *ppos)
170{ 172{
171 if (count) { 173 if (count) {
172 if (!nowayout) { 174 if (!nowayout) {
@@ -188,77 +190,71 @@ ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppo
188 return count; 190 return count;
189} 191}
190 192
191static int 193static long ibwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
192ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
193 unsigned long arg)
194{ 194{
195 int new_margin; 195 int new_margin;
196 void __user *argp = (void __user *)arg; 196 void __user *argp = (void __user *)arg;
197 int __user *p = argp; 197 int __user *p = argp;
198 198
199 static struct watchdog_info ident = { 199 static struct watchdog_info ident = {
200 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, 200 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
201 | WDIOF_MAGICCLOSE,
201 .firmware_version = 1, 202 .firmware_version = 1,
202 .identity = "IB700 WDT", 203 .identity = "IB700 WDT",
203 }; 204 };
204 205
205 switch (cmd) { 206 switch (cmd) {
206 case WDIOC_GETSUPPORT: 207 case WDIOC_GETSUPPORT:
207 if (copy_to_user(argp, &ident, sizeof(ident))) 208 if (copy_to_user(argp, &ident, sizeof(ident)))
208 return -EFAULT; 209 return -EFAULT;
209 break; 210 break;
210 211
211 case WDIOC_GETSTATUS: 212 case WDIOC_GETSTATUS:
212 case WDIOC_GETBOOTSTATUS: 213 case WDIOC_GETBOOTSTATUS:
213 return put_user(0, p); 214 return put_user(0, p);
214 215
215 case WDIOC_KEEPALIVE: 216 case WDIOC_KEEPALIVE:
216 ibwdt_ping(); 217 ibwdt_ping();
217 break; 218 break;
218 219
219 case WDIOC_SETTIMEOUT: 220 case WDIOC_SETTIMEOUT:
220 if (get_user(new_margin, p)) 221 if (get_user(new_margin, p))
221 return -EFAULT; 222 return -EFAULT;
222 if (ibwdt_set_heartbeat(new_margin)) 223 if (ibwdt_set_heartbeat(new_margin))
223 return -EINVAL; 224 return -EINVAL;
224 ibwdt_ping(); 225 ibwdt_ping();
225 /* Fall */ 226 /* Fall */
226 227
227 case WDIOC_GETTIMEOUT: 228 case WDIOC_GETTIMEOUT:
228 return put_user(wd_times[wd_margin], p); 229 return put_user(wd_times[wd_margin], p);
229 230
230 case WDIOC_SETOPTIONS: 231 case WDIOC_SETOPTIONS:
231 { 232 {
232 int options, retval = -EINVAL; 233 int options, retval = -EINVAL;
233 234
234 if (get_user(options, p)) 235 if (get_user(options, p))
235 return -EFAULT; 236 return -EFAULT;
236 237
237 if (options & WDIOS_DISABLECARD) { 238 if (options & WDIOS_DISABLECARD) {
238 ibwdt_disable(); 239 ibwdt_disable();
239 retval = 0; 240 retval = 0;
240 } 241 }
241 242 if (options & WDIOS_ENABLECARD) {
242 if (options & WDIOS_ENABLECARD) { 243 ibwdt_ping();
243 ibwdt_ping(); 244 retval = 0;
244 retval = 0; 245 }
245 } 246 return retval;
246
247 return retval;
248 } 247 }
249
250 default: 248 default:
251 return -ENOTTY; 249 return -ENOTTY;
252 } 250 }
253 return 0; 251 return 0;
254} 252}
255 253
256static int 254static int ibwdt_open(struct inode *inode, struct file *file)
257ibwdt_open(struct inode *inode, struct file *file)
258{ 255{
259 if (test_and_set_bit(0, &ibwdt_is_open)) { 256 if (test_and_set_bit(0, &ibwdt_is_open))
260 return -EBUSY; 257 return -EBUSY;
261 }
262 if (nowayout) 258 if (nowayout)
263 __module_get(THIS_MODULE); 259 __module_get(THIS_MODULE);
264 260
@@ -273,7 +269,8 @@ ibwdt_close(struct inode *inode, struct file *file)
273 if (expect_close == 42) { 269 if (expect_close == 42) {
274 ibwdt_disable(); 270 ibwdt_disable();
275 } else { 271 } else {
276 printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); 272 printk(KERN_CRIT PFX
273 "WDT device closed unexpectedly. WDT will not stop!\n");
277 ibwdt_ping(); 274 ibwdt_ping();
278 } 275 }
279 clear_bit(0, &ibwdt_is_open); 276 clear_bit(0, &ibwdt_is_open);
@@ -289,7 +286,7 @@ static const struct file_operations ibwdt_fops = {
289 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
290 .llseek = no_llseek, 287 .llseek = no_llseek,
291 .write = ibwdt_write, 288 .write = ibwdt_write,
292 .ioctl = ibwdt_ioctl, 289 .unlocked_ioctl = ibwdt_ioctl,
293 .open = ibwdt_open, 290 .open = ibwdt_open,
294 .release = ibwdt_close, 291 .release = ibwdt_close,
295}; 292};
@@ -310,21 +307,23 @@ static int __devinit ibwdt_probe(struct platform_device *dev)
310 307
311#if WDT_START != WDT_STOP 308#if WDT_START != WDT_STOP
312 if (!request_region(WDT_STOP, 1, "IB700 WDT")) { 309 if (!request_region(WDT_STOP, 1, "IB700 WDT")) {
313 printk (KERN_ERR PFX "STOP method I/O %X is not available.\n", WDT_STOP); 310 printk(KERN_ERR PFX "STOP method I/O %X is not available.\n",
311 WDT_STOP);
314 res = -EIO; 312 res = -EIO;
315 goto out_nostopreg; 313 goto out_nostopreg;
316 } 314 }
317#endif 315#endif
318 316
319 if (!request_region(WDT_START, 1, "IB700 WDT")) { 317 if (!request_region(WDT_START, 1, "IB700 WDT")) {
320 printk (KERN_ERR PFX "START method I/O %X is not available.\n", WDT_START); 318 printk(KERN_ERR PFX "START method I/O %X is not available.\n",
319 WDT_START);
321 res = -EIO; 320 res = -EIO;
322 goto out_nostartreg; 321 goto out_nostartreg;
323 } 322 }
324 323
325 res = misc_register(&ibwdt_miscdev); 324 res = misc_register(&ibwdt_miscdev);
326 if (res) { 325 if (res) {
327 printk (KERN_ERR PFX "failed to register misc device\n"); 326 printk(KERN_ERR PFX "failed to register misc device\n");
328 goto out_nomisc; 327 goto out_nomisc;
329 } 328 }
330 return 0; 329 return 0;
@@ -342,9 +341,9 @@ out_nostopreg:
342static int __devexit ibwdt_remove(struct platform_device *dev) 341static int __devexit ibwdt_remove(struct platform_device *dev)
343{ 342{
344 misc_deregister(&ibwdt_miscdev); 343 misc_deregister(&ibwdt_miscdev);
345 release_region(WDT_START,1); 344 release_region(WDT_START, 1);
346#if WDT_START != WDT_STOP 345#if WDT_START != WDT_STOP
347 release_region(WDT_STOP,1); 346 release_region(WDT_STOP, 1);
348#endif 347#endif
349 return 0; 348 return 0;
350} 349}
@@ -369,13 +368,15 @@ static int __init ibwdt_init(void)
369{ 368{
370 int err; 369 int err;
371 370
372 printk(KERN_INFO PFX "WDT driver for IB700 single board computer initialising.\n"); 371 printk(KERN_INFO PFX
372 "WDT driver for IB700 single board computer initialising.\n");
373 373
374 err = platform_driver_register(&ibwdt_driver); 374 err = platform_driver_register(&ibwdt_driver);
375 if (err) 375 if (err)
376 return err; 376 return err;
377 377
378 ibwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); 378 ibwdt_platform_device = platform_device_register_simple(DRV_NAME,
379 -1, NULL, 0);
379 if (IS_ERR(ibwdt_platform_device)) { 380 if (IS_ERR(ibwdt_platform_device)) {
380 err = PTR_ERR(ibwdt_platform_device); 381 err = PTR_ERR(ibwdt_platform_device);
381 goto unreg_platform_driver; 382 goto unreg_platform_driver;