[WATCHDOG 52/57] w83977f_wdt: clean up, coding style 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>
This commit is contained in:
committed by
Wim Van Sebroeck
parent
c1cfd1a2ff
commit
84af401af8
@@ -26,10 +26,10 @@
|
|||||||
#include <linux/watchdog.h>
|
#include <linux/watchdog.h>
|
||||||
#include <linux/notifier.h>
|
#include <linux/notifier.h>
|
||||||
#include <linux/reboot.h>
|
#include <linux/reboot.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
|
#include <linux/io.h>
|
||||||
|
|
||||||
#include <asm/io.h>
|
|
||||||
#include <asm/system.h>
|
#include <asm/system.h>
|
||||||
#include <asm/uaccess.h>
|
|
||||||
|
|
||||||
#define WATCHDOG_VERSION "1.00"
|
#define WATCHDOG_VERSION "1.00"
|
||||||
#define WATCHDOG_NAME "W83977F WDT"
|
#define WATCHDOG_NAME "W83977F WDT"
|
||||||
@@ -53,13 +53,17 @@ static char expect_close;
|
|||||||
static DEFINE_SPINLOCK(spinlock);
|
static DEFINE_SPINLOCK(spinlock);
|
||||||
|
|
||||||
module_param(timeout, int, 0);
|
module_param(timeout, int, 0);
|
||||||
MODULE_PARM_DESC(timeout,"Watchdog timeout in seconds (15..7635), default=" __MODULE_STRING(DEFAULT_TIMEOUT) ")");
|
MODULE_PARM_DESC(timeout,
|
||||||
|
"Watchdog timeout in seconds (15..7635), default="
|
||||||
|
__MODULE_STRING(DEFAULT_TIMEOUT) ")");
|
||||||
module_param(testmode, int, 0);
|
module_param(testmode, int, 0);
|
||||||
MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
|
MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
|
||||||
|
|
||||||
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) ")");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the watchdog
|
* Start the watchdog
|
||||||
@@ -103,8 +107,7 @@ static int wdt_start(void)
|
|||||||
*/
|
*/
|
||||||
outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
|
outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
|
||||||
outb_p(0x07, IO_DATA_PORT);
|
outb_p(0x07, IO_DATA_PORT);
|
||||||
if (!testmode)
|
if (!testmode) {
|
||||||
{
|
|
||||||
unsigned pin_map;
|
unsigned pin_map;
|
||||||
|
|
||||||
outb_p(0xE6, IO_INDEX_PORT);
|
outb_p(0xE6, IO_INDEX_PORT);
|
||||||
@@ -170,8 +173,7 @@ static int wdt_stop(void)
|
|||||||
*/
|
*/
|
||||||
outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
|
outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
|
||||||
outb_p(0x07, IO_DATA_PORT);
|
outb_p(0x07, IO_DATA_PORT);
|
||||||
if (!testmode)
|
if (!testmode) {
|
||||||
{
|
|
||||||
outb_p(0xE6, IO_INDEX_PORT);
|
outb_p(0xE6, IO_INDEX_PORT);
|
||||||
outb_p(0x01, IO_DATA_PORT);
|
outb_p(0x01, IO_DATA_PORT);
|
||||||
}
|
}
|
||||||
@@ -306,13 +308,13 @@ static int wdt_release(struct inode *inode, struct file *file)
|
|||||||
* Shut off the timer.
|
* Shut off the timer.
|
||||||
* Lock it in if it's a module and we set nowayout
|
* Lock it in if it's a module and we set nowayout
|
||||||
*/
|
*/
|
||||||
if (expect_close == 42)
|
if (expect_close == 42) {
|
||||||
{
|
|
||||||
wdt_stop();
|
wdt_stop();
|
||||||
clear_bit(0, &timer_alive);
|
clear_bit(0, &timer_alive);
|
||||||
} else {
|
} else {
|
||||||
wdt_keepalive();
|
wdt_keepalive();
|
||||||
printk(KERN_CRIT PFX "unexpected close, not stopping watchdog!\n");
|
printk(KERN_CRIT PFX
|
||||||
|
"unexpected close, not stopping watchdog!\n");
|
||||||
}
|
}
|
||||||
expect_close = 0;
|
expect_close = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -333,26 +335,24 @@ static ssize_t wdt_write(struct file *file, const char __user *buf,
|
|||||||
size_t count, loff_t *ppos)
|
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) {
|
||||||
{
|
if (!nowayout) {
|
||||||
if (!nowayout)
|
|
||||||
{
|
|
||||||
size_t ofs;
|
size_t ofs;
|
||||||
|
|
||||||
/* note: just in case someone wrote the magic character long ago */
|
/* note: just in case someone wrote the
|
||||||
|
magic character 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
|
||||||
for(ofs = 0; ofs != count; ofs++)
|
magic character */
|
||||||
{
|
for (ofs = 0; ofs != count; ofs++) {
|
||||||
char c;
|
char c;
|
||||||
if (get_user(c, buf + ofs))
|
if (get_user(c, buf + ofs))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (c == 'V') {
|
if (c == 'V')
|
||||||
expect_close = 42;
|
expect_close = 42;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* someone wrote to us, we should restart timer */
|
/* someone wrote to us, we should restart timer */
|
||||||
wdt_keepalive();
|
wdt_keepalive();
|
||||||
@@ -377,8 +377,7 @@ static struct watchdog_info ident = {
|
|||||||
.identity = WATCHDOG_NAME,
|
.identity = WATCHDOG_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int wdt_ioctl(struct inode *inode, struct file *file,
|
static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||||
unsigned int cmd, unsigned long arg)
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int new_options, retval = -EINVAL;
|
int new_options, retval = -EINVAL;
|
||||||
@@ -390,13 +389,13 @@ static int wdt_ioctl(struct inode *inode, struct file *file,
|
|||||||
|
|
||||||
uarg.i = (int __user *)arg;
|
uarg.i = (int __user *)arg;
|
||||||
|
|
||||||
switch(cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
default:
|
default:
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
|
|
||||||
case WDIOC_GETSUPPORT:
|
case WDIOC_GETSUPPORT:
|
||||||
return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0;
|
return copy_to_user(uarg.ident, &ident,
|
||||||
|
sizeof(ident)) ? -EFAULT : 0;
|
||||||
|
|
||||||
case WDIOC_GETSTATUS:
|
case WDIOC_GETSTATUS:
|
||||||
wdt_get_status(&status);
|
wdt_get_status(&status);
|
||||||
@@ -449,18 +448,16 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
|
|||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations wdt_fops=
|
static const struct file_operations wdt_fops = {
|
||||||
{
|
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.llseek = no_llseek,
|
.llseek = no_llseek,
|
||||||
.write = wdt_write,
|
.write = wdt_write,
|
||||||
.ioctl = wdt_ioctl,
|
.unlocked_ioctl = wdt_ioctl,
|
||||||
.open = wdt_open,
|
.open = wdt_open,
|
||||||
.release = wdt_release,
|
.release = wdt_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct miscdevice wdt_miscdev=
|
static struct miscdevice wdt_miscdev = {
|
||||||
{
|
|
||||||
.minor = WATCHDOG_MINOR,
|
.minor = WATCHDOG_MINOR,
|
||||||
.name = "watchdog",
|
.name = "watchdog",
|
||||||
.fops = &wdt_fops,
|
.fops = &wdt_fops,
|
||||||
@@ -482,12 +479,12 @@ static int __init w83977f_wdt_init(void)
|
|||||||
*/
|
*/
|
||||||
if (wdt_set_timeout(timeout)) {
|
if (wdt_set_timeout(timeout)) {
|
||||||
wdt_set_timeout(DEFAULT_TIMEOUT);
|
wdt_set_timeout(DEFAULT_TIMEOUT);
|
||||||
printk(KERN_INFO PFX "timeout value must be 15<=timeout<=7635, using %d\n",
|
printk(KERN_INFO PFX
|
||||||
|
"timeout value must be 15 <= timeout <= 7635, using %d\n",
|
||||||
DEFAULT_TIMEOUT);
|
DEFAULT_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME))
|
if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
|
||||||
{
|
|
||||||
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",
|
||||||
IO_INDEX_PORT);
|
IO_INDEX_PORT);
|
||||||
rc = -EIO;
|
rc = -EIO;
|
||||||
@@ -495,22 +492,22 @@ static int __init w83977f_wdt_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = register_reboot_notifier(&wdt_notifier);
|
rc = register_reboot_notifier(&wdt_notifier);
|
||||||
if (rc)
|
if (rc) {
|
||||||
{
|
printk(KERN_ERR PFX
|
||||||
printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
|
"cannot register reboot notifier (err=%d)\n", rc);
|
||||||
rc);
|
|
||||||
goto err_out_region;
|
goto err_out_region;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = misc_register(&wdt_miscdev);
|
rc = misc_register(&wdt_miscdev);
|
||||||
if (rc)
|
if (rc) {
|
||||||
{
|
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",
|
||||||
wdt_miscdev.minor, rc);
|
wdt_miscdev.minor, rc);
|
||||||
goto err_out_reboot;
|
goto err_out_reboot;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d testmode=%d)\n",
|
printk(KERN_INFO PFX
|
||||||
|
"initialized. timeout=%d sec (nowayout=%d testmode=%d)\n",
|
||||||
timeout, nowayout, testmode);
|
timeout, nowayout, testmode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user