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

[WATCHDOG 53/57] wafer5823wdt: Clean up, coding style, 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 84af401a
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#define WATCHDOG_NAME "Wafer 5823 WDT" #define WATCHDOG_NAME "Wafer 5823 WDT"
#define PFX WATCHDOG_NAME ": " #define PFX WATCHDOG_NAME ": "
...@@ -61,11 +61,15 @@ static int wdt_start = 0x443; ...@@ -61,11 +61,15 @@ static int wdt_start = 0x443;
static int timeout = WD_TIMO; /* in seconds */ static int timeout = WD_TIMO; /* in seconds */
module_param(timeout, int, 0); module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WD_TIMO) "."); MODULE_PARM_DESC(timeout,
"Watchdog timeout in seconds. 1 <= timeout <= 255, default="
__MODULE_STRING(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) ")");
static void wafwdt_ping(void) static void wafwdt_ping(void)
{ {
...@@ -90,7 +94,8 @@ wafwdt_stop(void) ...@@ -90,7 +94,8 @@ wafwdt_stop(void)
inb_p(wdt_stop); inb_p(wdt_stop);
} }
static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos) static ssize_t wafwdt_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{ {
/* See if we got the magic character 'V' and reload the timer */ /* See if we got the magic character 'V' and reload the timer */
if (count) { if (count) {
...@@ -100,7 +105,8 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co ...@@ -100,7 +105,8 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co
/* In case it was set long ago */ /* In case it was set long ago */
expect_close = 0; expect_close = 0;
/* scan to see whether or not we got the magic character */ /* scan to see whether or not we got the magic
character */
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))
...@@ -109,27 +115,29 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co ...@@ -109,27 +115,29 @@ static ssize_t wafwdt_write(struct file *file, const char __user *buf, size_t co
expect_close = 42; expect_close = 42;
} }
} }
/* Well, anyhow someone wrote to us, we should return that favour */ /* Well, anyhow someone wrote to us, we should
return that favour */
wafwdt_ping(); wafwdt_ping();
} }
return count; return count;
} }
static int wafwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static long wafwdt_ioctl(struct file *file, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
int new_timeout; int new_timeout;
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 const 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 = "Wafer 5823 WDT", .identity = "Wafer 5823 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;
...@@ -194,10 +202,11 @@ static int wafwdt_open(struct inode *inode, struct file *file) ...@@ -194,10 +202,11 @@ static int wafwdt_open(struct inode *inode, struct file *file)
static int static int
wafwdt_close(struct inode *inode, struct file *file) wafwdt_close(struct inode *inode, struct file *file)
{ {
if (expect_close == 42) { if (expect_close == 42)
wafwdt_stop(); wafwdt_stop();
} 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");
wafwdt_ping(); wafwdt_ping();
} }
clear_bit(0, &wafwdt_is_open); clear_bit(0, &wafwdt_is_open);
...@@ -209,12 +218,11 @@ wafwdt_close(struct inode *inode, struct file *file) ...@@ -209,12 +218,11 @@ wafwdt_close(struct inode *inode, struct file *file)
* Notifier for system down * Notifier for system down
*/ */
static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code,
void *unused)
{ {
if (code == SYS_DOWN || code == SYS_HALT) { if (code == SYS_DOWN || code == SYS_HALT)
/* Turn the WDT off */
wafwdt_stop(); wafwdt_stop();
}
return NOTIFY_DONE; return NOTIFY_DONE;
} }
...@@ -226,7 +234,7 @@ static const struct file_operations wafwdt_fops = { ...@@ -226,7 +234,7 @@ static const struct file_operations wafwdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = wafwdt_write, .write = wafwdt_write,
.ioctl = wafwdt_ioctl, .unlocked_ioctl = wafwdt_ioctl,
.open = wafwdt_open, .open = wafwdt_open,
.release = wafwdt_close, .release = wafwdt_close,
}; };
...@@ -250,25 +258,28 @@ static int __init wafwdt_init(void) ...@@ -250,25 +258,28 @@ static int __init wafwdt_init(void)
{ {
int ret; int ret;
printk(KERN_INFO "WDT driver for Wafer 5823 single board computer initialising.\n"); printk(KERN_INFO
"WDT driver for Wafer 5823 single board computer initialising.\n");
if (timeout < 1 || timeout > 255) { if (timeout < 1 || timeout > 255) {
timeout = WD_TIMO; timeout = WD_TIMO;
printk (KERN_INFO PFX "timeout value must be 1<=x<=255, using %d\n", printk(KERN_INFO PFX
"timeout value must be 1 <= x <= 255, using %d\n",
timeout); timeout);
} }
if (wdt_stop != wdt_start) { if (wdt_stop != wdt_start) {
if(!request_region(wdt_stop, 1, "Wafer 5823 WDT")) { if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) {
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", printk(KERN_ERR PFX
"I/O address 0x%04x already in use\n",
wdt_stop); wdt_stop);
ret = -EIO; ret = -EIO;
goto error; goto error;
} }
} }
if(!request_region(wdt_start, 1, "Wafer 5823 WDT")) { if (!request_region(wdt_start, 1, "Wafer 5823 WDT")) {
printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
wdt_start); wdt_start);
ret = -EIO; ret = -EIO;
goto error2; goto error2;
...@@ -276,19 +287,20 @@ static int __init wafwdt_init(void) ...@@ -276,19 +287,20 @@ static int __init wafwdt_init(void)
ret = register_reboot_notifier(&wafwdt_notifier); ret = register_reboot_notifier(&wafwdt_notifier);
if (ret != 0) { if (ret != 0) {
printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX
ret); "cannot register reboot notifier (err=%d)\n", ret);
goto error3; goto error3;
} }
ret = misc_register(&wafwdt_miscdev); ret = misc_register(&wafwdt_miscdev);
if (ret != 0) { if (ret != 0) {
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", printk(KERN_ERR PFX
"cannot register miscdev on minor=%d (err=%d)\n",
WATCHDOG_MINOR, ret); WATCHDOG_MINOR, ret);
goto error4; goto error4;
} }
printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n", printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
timeout, nowayout); timeout, nowayout);
return ret; return ret;
...@@ -307,7 +319,7 @@ static void __exit wafwdt_exit(void) ...@@ -307,7 +319,7 @@ static void __exit wafwdt_exit(void)
{ {
misc_deregister(&wafwdt_miscdev); misc_deregister(&wafwdt_miscdev);
unregister_reboot_notifier(&wafwdt_notifier); unregister_reboot_notifier(&wafwdt_notifier);
if(wdt_stop != wdt_start) if (wdt_stop != wdt_start)
release_region(wdt_stop, 1); release_region(wdt_stop, 1);
release_region(wdt_start, 1); release_region(wdt_start, 1);
} }
......
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