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

[WATCHDOG 10/57] eurotechwdt: unlocked_ioctl, code lock check and tidy

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 f339e2ac
...@@ -56,14 +56,15 @@ ...@@ -56,14 +56,15 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
static unsigned long eurwdt_is_open; static unsigned long eurwdt_is_open;
static int eurwdt_timeout; static int eurwdt_timeout;
static char eur_expect_close; static char eur_expect_close;
static spinlock_t eurwdt_lock;
/* /*
* You must set these - there is no sane way to probe for this board. * You must set these - there is no sane way to probe for this board.
...@@ -78,7 +79,9 @@ static char *ev = "int"; ...@@ -78,7 +79,9 @@ static char *ev = "int";
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) ")");
/* /*
* Some symbolic names * Some symbolic names
...@@ -137,7 +140,8 @@ static void eurwdt_activate_timer(void) ...@@ -137,7 +140,8 @@ static void eurwdt_activate_timer(void)
{ {
eurwdt_disable_timer(); eurwdt_disable_timer();
eurwdt_write_reg(WDT_CTRL_REG, 0x01); /* activate the WDT */ eurwdt_write_reg(WDT_CTRL_REG, 0x01); /* activate the WDT */
eurwdt_write_reg(WDT_OUTPIN_CFG, !strcmp("int", ev) ? WDT_EVENT_INT : WDT_EVENT_REBOOT); eurwdt_write_reg(WDT_OUTPIN_CFG,
!strcmp("int", ev) ? WDT_EVENT_INT : WDT_EVENT_REBOOT);
/* Setting interrupt line */ /* Setting interrupt line */
if (irq == 2 || irq > 15 || irq < 0) { if (irq == 2 || irq > 15 || irq < 0) {
...@@ -206,21 +210,21 @@ size_t count, loff_t *ppos) ...@@ -206,21 +210,21 @@ size_t count, loff_t *ppos)
for (i = 0; i != count; i++) { for (i = 0; i != count; i++) {
char c; char c;
if(get_user(c, buf+i)) if (get_user(c, buf+i))
return -EFAULT; return -EFAULT;
if (c == 'V') if (c == 'V')
eur_expect_close = 42; eur_expect_close = 42;
} }
} }
spin_lock(&eurwdt_lock);
eurwdt_ping(); /* the default timeout */ eurwdt_ping(); /* the default timeout */
spin_unlock(&eurwdt_lock);
} }
return count; return count;
} }
/** /**
* eurwdt_ioctl: * eurwdt_ioctl:
* @inode: inode of the device
* @file: file handle to the device * @file: file handle to the device
* @cmd: watchdog command * @cmd: watchdog command
* @arg: argument pointer * @arg: argument pointer
...@@ -229,13 +233,14 @@ size_t count, loff_t *ppos) ...@@ -229,13 +233,14 @@ size_t count, loff_t *ppos)
* according to their available features. * according to their available features.
*/ */
static int eurwdt_ioctl(struct inode *inode, struct file *file, static long eurwdt_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;
int __user *p = argp; int __user *p = argp;
static struct watchdog_info ident = { static struct watchdog_info ident = {
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
| WDIOF_MAGICCLOSE,
.firmware_version = 1, .firmware_version = 1,
.identity = "WDT Eurotech CPU-1220/1410", .identity = "WDT Eurotech CPU-1220/1410",
}; };
...@@ -243,7 +248,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file, ...@@ -243,7 +248,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
int time; int time;
int options, retval = -EINVAL; int options, retval = -EINVAL;
switch(cmd) { switch (cmd) {
default: default:
return -ENOTTY; return -ENOTTY;
...@@ -255,7 +260,9 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file, ...@@ -255,7 +260,9 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
return put_user(0, p); return put_user(0, p);
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
spin_lock(&eurwdt_lock);
eurwdt_ping(); eurwdt_ping();
spin_unlock(&eurwdt_lock);
return 0; return 0;
case WDIOC_SETTIMEOUT: case WDIOC_SETTIMEOUT:
...@@ -266,8 +273,10 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file, ...@@ -266,8 +273,10 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
if (time < 0 || time > 255) if (time < 0 || time > 255)
return -EINVAL; return -EINVAL;
spin_lock(&eurwdt_lock);
eurwdt_timeout = time; eurwdt_timeout = time;
eurwdt_set_timeout(time); eurwdt_set_timeout(time);
spin_unlock(&eurwdt_lock);
/* Fall */ /* Fall */
case WDIOC_GETTIMEOUT: case WDIOC_GETTIMEOUT:
...@@ -276,6 +285,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file, ...@@ -276,6 +285,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
case WDIOC_SETOPTIONS: case WDIOC_SETOPTIONS:
if (get_user(options, p)) if (get_user(options, p))
return -EFAULT; return -EFAULT;
spin_lock(&eurwdt_lock);
if (options & WDIOS_DISABLECARD) { if (options & WDIOS_DISABLECARD) {
eurwdt_disable_timer(); eurwdt_disable_timer();
retval = 0; retval = 0;
...@@ -285,6 +295,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file, ...@@ -285,6 +295,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
eurwdt_ping(); eurwdt_ping();
retval = 0; retval = 0;
} }
spin_unlock(&eurwdt_lock);
return retval; return retval;
} }
} }
...@@ -322,10 +333,11 @@ static int eurwdt_open(struct inode *inode, struct file *file) ...@@ -322,10 +333,11 @@ static int eurwdt_open(struct inode *inode, struct file *file)
static int eurwdt_release(struct inode *inode, struct file *file) static int eurwdt_release(struct inode *inode, struct file *file)
{ {
if (eur_expect_close == 42) { if (eur_expect_close == 42)
eurwdt_disable_timer(); eurwdt_disable_timer();
} else { else {
printk(KERN_CRIT "eurwdt: Unexpected close, not stopping watchdog!\n"); printk(KERN_CRIT
"eurwdt: Unexpected close, not stopping watchdog!\n");
eurwdt_ping(); eurwdt_ping();
} }
clear_bit(0, &eurwdt_is_open); clear_bit(0, &eurwdt_is_open);
...@@ -365,7 +377,7 @@ static const struct file_operations eurwdt_fops = { ...@@ -365,7 +377,7 @@ static const struct file_operations eurwdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = eurwdt_write, .write = eurwdt_write,
.ioctl = eurwdt_ioctl, .unlocked_ioctl = eurwdt_ioctl,
.open = eurwdt_open, .open = eurwdt_open,
.release = eurwdt_release, .release = eurwdt_release,
}; };
...@@ -419,7 +431,7 @@ static int __init eurwdt_init(void) ...@@ -419,7 +431,7 @@ static int __init eurwdt_init(void)
int ret; int ret;
ret = request_irq(irq, eurwdt_interrupt, IRQF_DISABLED, "eurwdt", NULL); ret = request_irq(irq, eurwdt_interrupt, IRQF_DISABLED, "eurwdt", NULL);
if(ret) { if (ret) {
printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq); printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq);
goto out; goto out;
} }
...@@ -432,10 +444,13 @@ static int __init eurwdt_init(void) ...@@ -432,10 +444,13 @@ static int __init eurwdt_init(void)
ret = register_reboot_notifier(&eurwdt_notifier); ret = register_reboot_notifier(&eurwdt_notifier);
if (ret) { if (ret) {
printk(KERN_ERR "eurwdt: can't register reboot notifier (err=%d)\n", ret); printk(KERN_ERR
"eurwdt: can't register reboot notifier (err=%d)\n", ret);
goto outreg; goto outreg;
} }
spin_lock_init(&eurwdt_lock);
ret = misc_register(&eurwdt_miscdev); ret = misc_register(&eurwdt_miscdev);
if (ret) { if (ret) {
printk(KERN_ERR "eurwdt: can't misc_register on minor=%d\n", printk(KERN_ERR "eurwdt: can't misc_register on minor=%d\n",
......
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