Commit 39309645 authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

[WATCHDOG 25/57] mixcomwd: coding style locking, unlocked_ioctl

Review and switch to unlocked_ioctl
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 325ea4d3
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
* - support for one more type board * - support for one more type board
* *
* Version 0.5 (2001/12/14) Matt Domsch <Matt_Domsch@dell.com> * Version 0.5 (2001/12/14) Matt Domsch <Matt_Domsch@dell.com>
* - added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT * - added nowayout module option to override
* CONFIG_WATCHDOG_NOWAYOUT
* *
* Version 0.6 (2002/04/12): Rob Radez <rob@osinvestor.com> * Version 0.6 (2002/04/12): Rob Radez <rob@osinvestor.com>
* - make mixcomwd_opened unsigned, * - make mixcomwd_opened unsigned,
...@@ -53,8 +54,8 @@ ...@@ -53,8 +54,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/io.h> #include <linux/io.h>
/* /*
* We have two types of cards that can be probed: * We have two types of cards that can be probed:
...@@ -108,18 +109,19 @@ static char expect_close; ...@@ -108,18 +109,19 @@ static char expect_close;
static int nowayout = WATCHDOG_NOWAYOUT; static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0); module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
static void mixcomwd_ping(void) static void mixcomwd_ping(void)
{ {
outb_p(55,watchdog_port); outb_p(55, watchdog_port);
return; return;
} }
static void mixcomwd_timerfun(unsigned long d) static void mixcomwd_timerfun(unsigned long d)
{ {
mixcomwd_ping(); mixcomwd_ping();
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ); mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
} }
...@@ -129,22 +131,22 @@ static void mixcomwd_timerfun(unsigned long d) ...@@ -129,22 +131,22 @@ static void mixcomwd_timerfun(unsigned long d)
static int mixcomwd_open(struct inode *inode, struct file *file) static int mixcomwd_open(struct inode *inode, struct file *file)
{ {
if(test_and_set_bit(0,&mixcomwd_opened)) { if (test_and_set_bit(0, &mixcomwd_opened))
return -EBUSY; return -EBUSY;
}
mixcomwd_ping(); mixcomwd_ping();
if (nowayout) { if (nowayout)
/* /*
* fops_get() code via open() has already done * fops_get() code via open() has already done
* a try_module_get() so it is safe to do the * a try_module_get() so it is safe to do the
* __module_get(). * __module_get().
*/ */
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
} else { else {
if(mixcomwd_timer_alive) { if (mixcomwd_timer_alive) {
del_timer(&mixcomwd_timer); del_timer(&mixcomwd_timer);
mixcomwd_timer_alive=0; mixcomwd_timer_alive = 0;
} }
} }
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
...@@ -153,26 +155,27 @@ static int mixcomwd_open(struct inode *inode, struct file *file) ...@@ -153,26 +155,27 @@ static int mixcomwd_open(struct inode *inode, struct file *file)
static int mixcomwd_release(struct inode *inode, struct file *file) static int mixcomwd_release(struct inode *inode, struct file *file)
{ {
if (expect_close == 42) { if (expect_close == 42) {
if(mixcomwd_timer_alive) { if (mixcomwd_timer_alive) {
printk(KERN_ERR PFX "release called while internal timer alive"); printk(KERN_ERR PFX
"release called while internal timer alive");
return -EBUSY; return -EBUSY;
} }
mixcomwd_timer_alive=1; mixcomwd_timer_alive = 1;
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ); mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
} else { } else
printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); printk(KERN_CRIT PFX
} "WDT device closed unexpectedly. WDT will not stop!\n");
clear_bit(0,&mixcomwd_opened); clear_bit(0, &mixcomwd_opened);
expect_close=0; expect_close = 0;
return 0; return 0;
} }
static ssize_t mixcomwd_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) static ssize_t mixcomwd_write(struct file *file, const char __user *data,
size_t len, loff_t *ppos)
{ {
if(len) if (len) {
{
if (!nowayout) { if (!nowayout) {
size_t i; size_t i;
...@@ -192,7 +195,7 @@ static ssize_t mixcomwd_write(struct file *file, const char __user *data, size_t ...@@ -192,7 +195,7 @@ static ssize_t mixcomwd_write(struct file *file, const char __user *data, size_t
return len; return len;
} }
static int mixcomwd_ioctl(struct inode *inode, struct file *file, static long mixcomwd_ioctl(struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
...@@ -204,26 +207,17 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file, ...@@ -204,26 +207,17 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file,
.identity = "MixCOM watchdog", .identity = "MixCOM watchdog",
}; };
switch(cmd) switch (cmd) {
{
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
status=mixcomwd_opened; status = mixcomwd_opened;
if (!nowayout) { if (!nowayout)
status|=mixcomwd_timer_alive; status |= mixcomwd_timer_alive;
} return put_user(status, p);
if (copy_to_user(p, &status, sizeof(int))) {
return -EFAULT;
}
break;
case WDIOC_GETBOOTSTATUS: case WDIOC_GETBOOTSTATUS:
if (copy_to_user(p, &status, sizeof(int))) { return put_user(0, p);
return -EFAULT;
}
break;
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
if (copy_to_user(argp, &ident, sizeof(ident))) { if (copy_to_user(argp, &ident, sizeof(ident)))
return -EFAULT; return -EFAULT;
}
break; break;
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
mixcomwd_ping(); mixcomwd_ping();
...@@ -238,7 +232,7 @@ static const struct file_operations mixcomwd_fops = { ...@@ -238,7 +232,7 @@ static const struct file_operations mixcomwd_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = mixcomwd_write, .write = mixcomwd_write,
.ioctl = mixcomwd_ioctl, .unlocked_ioctl = mixcomwd_ioctl,
.open = mixcomwd_open, .open = mixcomwd_open,
.release = mixcomwd_release, .release = mixcomwd_release,
}; };
...@@ -253,15 +247,14 @@ static int __init checkcard(int port, int card_id) ...@@ -253,15 +247,14 @@ static int __init checkcard(int port, int card_id)
{ {
int id; int id;
if (!request_region(port, 1, "MixCOM watchdog")) { if (!request_region(port, 1, "MixCOM watchdog"))
return 0; return 0;
}
id=inb_p(port); id = inb_p(port);
if (card_id==MIXCOM_ID) if (card_id == MIXCOM_ID)
id &= 0x3f; id &= 0x3f;
if (id!=card_id) { if (id != card_id) {
release_region(port, 1); release_region(port, 1);
return 0; return 0;
} }
...@@ -270,9 +263,7 @@ static int __init checkcard(int port, int card_id) ...@@ -270,9 +263,7 @@ static int __init checkcard(int port, int card_id)
static int __init mixcomwd_init(void) static int __init mixcomwd_init(void)
{ {
int i; int i, ret, found = 0;
int ret;
int found=0;
for (i = 0; !found && mixcomwd_io_info[i].ioport != 0; i++) { for (i = 0; !found && mixcomwd_io_info[i].ioport != 0; i++) {
if (checkcard(mixcomwd_io_info[i].ioport, if (checkcard(mixcomwd_io_info[i].ioport,
...@@ -283,19 +274,21 @@ static int __init mixcomwd_init(void) ...@@ -283,19 +274,21 @@ static int __init mixcomwd_init(void)
} }
if (!found) { if (!found) {
printk(KERN_ERR PFX "No card detected, or port not available.\n"); printk(KERN_ERR PFX
"No card detected, or port not available.\n");
return -ENODEV; return -ENODEV;
} }
ret = misc_register(&mixcomwd_miscdev); ret = misc_register(&mixcomwd_miscdev);
if (ret) if (ret) {
{ printk(KERN_ERR PFX
printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", "cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret);
goto error_misc_register_watchdog; goto error_misc_register_watchdog;
} }
printk(KERN_INFO "MixCOM watchdog driver v%s, watchdog port at 0x%3x\n", printk(KERN_INFO
"MixCOM watchdog driver v%s, watchdog port at 0x%3x\n",
VERSION, watchdog_port); VERSION, watchdog_port);
return 0; return 0;
...@@ -309,15 +302,15 @@ static int __init mixcomwd_init(void) ...@@ -309,15 +302,15 @@ static int __init mixcomwd_init(void)
static void __exit mixcomwd_exit(void) static void __exit mixcomwd_exit(void)
{ {
if (!nowayout) { if (!nowayout) {
if(mixcomwd_timer_alive) { if (mixcomwd_timer_alive) {
printk(KERN_WARNING PFX "I quit now, hardware will" printk(KERN_WARNING PFX "I quit now, hardware will"
" probably reboot!\n"); " probably reboot!\n");
del_timer_sync(&mixcomwd_timer); del_timer_sync(&mixcomwd_timer);
mixcomwd_timer_alive=0; mixcomwd_timer_alive = 0;
} }
} }
misc_deregister(&mixcomwd_miscdev); misc_deregister(&mixcomwd_miscdev);
release_region(watchdog_port,1); release_region(watchdog_port, 1);
} }
module_init(mixcomwd_init); module_init(mixcomwd_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment