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

[WATCHDOG 12/57] ib700wdt: clean up and switch to 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 6513e2a0
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
static struct platform_device *ibwdt_platform_device; static struct platform_device *ibwdt_platform_device;
...@@ -120,7 +120,9 @@ static int wd_margin = WD_TIMO; ...@@ -120,7 +120,9 @@ static int wd_margin = WD_TIMO;
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) ")");
/* /*
...@@ -165,8 +167,8 @@ ibwdt_set_heartbeat(int t) ...@@ -165,8 +167,8 @@ ibwdt_set_heartbeat(int t)
* /dev/watchdog handling * /dev/watchdog handling
*/ */
static ssize_t static ssize_t ibwdt_write(struct file *file, const char __user *buf,
ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
if (count) { if (count) {
if (!nowayout) { if (!nowayout) {
...@@ -188,77 +190,71 @@ ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppo ...@@ -188,77 +190,71 @@ ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppo
return count; return count;
} }
static int static long ibwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg)
{ {
int new_margin; int new_margin;
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 = "IB700 WDT", .identity = "IB700 WDT",
}; };
switch (cmd) { switch (cmd) {
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_GETSTATUS: case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS: case WDIOC_GETBOOTSTATUS:
return put_user(0, p); return put_user(0, p);
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
ibwdt_ping(); ibwdt_ping();
break; break;
case WDIOC_SETTIMEOUT: case WDIOC_SETTIMEOUT:
if (get_user(new_margin, p)) if (get_user(new_margin, p))
return -EFAULT; return -EFAULT;
if (ibwdt_set_heartbeat(new_margin)) if (ibwdt_set_heartbeat(new_margin))
return -EINVAL; return -EINVAL;
ibwdt_ping(); ibwdt_ping();
/* Fall */ /* Fall */
case WDIOC_GETTIMEOUT: case WDIOC_GETTIMEOUT:
return put_user(wd_times[wd_margin], p); return put_user(wd_times[wd_margin], p);
case WDIOC_SETOPTIONS: case WDIOC_SETOPTIONS:
{ {
int options, retval = -EINVAL; int options, retval = -EINVAL;
if (get_user(options, p)) if (get_user(options, p))
return -EFAULT; return -EFAULT;
if (options & WDIOS_DISABLECARD) { if (options & WDIOS_DISABLECARD) {
ibwdt_disable(); ibwdt_disable();
retval = 0; retval = 0;
} }
if (options & WDIOS_ENABLECARD) {
if (options & WDIOS_ENABLECARD) { ibwdt_ping();
ibwdt_ping(); retval = 0;
retval = 0; }
} return retval;
return retval;
} }
default: default:
return -ENOTTY; return -ENOTTY;
} }
return 0; return 0;
} }
static int static int ibwdt_open(struct inode *inode, struct file *file)
ibwdt_open(struct inode *inode, struct file *file)
{ {
if (test_and_set_bit(0, &ibwdt_is_open)) { if (test_and_set_bit(0, &ibwdt_is_open))
return -EBUSY; return -EBUSY;
}
if (nowayout) if (nowayout)
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
...@@ -273,7 +269,8 @@ ibwdt_close(struct inode *inode, struct file *file) ...@@ -273,7 +269,8 @@ ibwdt_close(struct inode *inode, struct file *file)
if (expect_close == 42) { if (expect_close == 42) {
ibwdt_disable(); ibwdt_disable();
} 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");
ibwdt_ping(); ibwdt_ping();
} }
clear_bit(0, &ibwdt_is_open); clear_bit(0, &ibwdt_is_open);
...@@ -289,7 +286,7 @@ static const struct file_operations ibwdt_fops = { ...@@ -289,7 +286,7 @@ static const struct file_operations ibwdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = ibwdt_write, .write = ibwdt_write,
.ioctl = ibwdt_ioctl, .unlocked_ioctl = ibwdt_ioctl,
.open = ibwdt_open, .open = ibwdt_open,
.release = ibwdt_close, .release = ibwdt_close,
}; };
...@@ -310,21 +307,23 @@ static int __devinit ibwdt_probe(struct platform_device *dev) ...@@ -310,21 +307,23 @@ static int __devinit ibwdt_probe(struct platform_device *dev)
#if WDT_START != WDT_STOP #if WDT_START != WDT_STOP
if (!request_region(WDT_STOP, 1, "IB700 WDT")) { if (!request_region(WDT_STOP, 1, "IB700 WDT")) {
printk (KERN_ERR PFX "STOP method I/O %X is not available.\n", WDT_STOP); printk(KERN_ERR PFX "STOP method I/O %X is not available.\n",
WDT_STOP);
res = -EIO; res = -EIO;
goto out_nostopreg; goto out_nostopreg;
} }
#endif #endif
if (!request_region(WDT_START, 1, "IB700 WDT")) { if (!request_region(WDT_START, 1, "IB700 WDT")) {
printk (KERN_ERR PFX "START method I/O %X is not available.\n", WDT_START); printk(KERN_ERR PFX "START method I/O %X is not available.\n",
WDT_START);
res = -EIO; res = -EIO;
goto out_nostartreg; goto out_nostartreg;
} }
res = misc_register(&ibwdt_miscdev); res = misc_register(&ibwdt_miscdev);
if (res) { if (res) {
printk (KERN_ERR PFX "failed to register misc device\n"); printk(KERN_ERR PFX "failed to register misc device\n");
goto out_nomisc; goto out_nomisc;
} }
return 0; return 0;
...@@ -342,9 +341,9 @@ static int __devinit ibwdt_probe(struct platform_device *dev) ...@@ -342,9 +341,9 @@ static int __devinit ibwdt_probe(struct platform_device *dev)
static int __devexit ibwdt_remove(struct platform_device *dev) static int __devexit ibwdt_remove(struct platform_device *dev)
{ {
misc_deregister(&ibwdt_miscdev); misc_deregister(&ibwdt_miscdev);
release_region(WDT_START,1); release_region(WDT_START, 1);
#if WDT_START != WDT_STOP #if WDT_START != WDT_STOP
release_region(WDT_STOP,1); release_region(WDT_STOP, 1);
#endif #endif
return 0; return 0;
} }
...@@ -369,13 +368,15 @@ static int __init ibwdt_init(void) ...@@ -369,13 +368,15 @@ static int __init ibwdt_init(void)
{ {
int err; int err;
printk(KERN_INFO PFX "WDT driver for IB700 single board computer initialising.\n"); printk(KERN_INFO PFX
"WDT driver for IB700 single board computer initialising.\n");
err = platform_driver_register(&ibwdt_driver); err = platform_driver_register(&ibwdt_driver);
if (err) if (err)
return err; return err;
ibwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); ibwdt_platform_device = platform_device_register_simple(DRV_NAME,
-1, NULL, 0);
if (IS_ERR(ibwdt_platform_device)) { if (IS_ERR(ibwdt_platform_device)) {
err = PTR_ERR(ibwdt_platform_device); err = PTR_ERR(ibwdt_platform_device);
goto unreg_platform_driver; goto unreg_platform_driver;
......
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