[WATCHDOG 13/57] i6300esb: Style, unlocked_ioctl, cleanup

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:
Alan Cox
2008-05-19 14:05:57 +01:00
committed by Wim Van Sebroeck
parent 2e43ba73d4
commit 0829291ea4

View File

@@ -38,9 +38,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/uaccess.h>
#include <asm/uaccess.h> #include <linux/io.h>
#include <asm/io.h>
/* Module and version information */ /* Module and version information */
#define ESB_VERSION "0.03" #define ESB_VERSION "0.03"
@@ -84,14 +83,20 @@ static unsigned short triggered; /* The status of the watchdog upon boot */
static char esb_expect_close; static char esb_expect_close;
/* module parameters */ /* module parameters */
#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat (1<heartbeat<2*1023) */ /* 30 sec default heartbeat (1 < heartbeat < 2*1023) */
#define WATCHDOG_HEARTBEAT 30
static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
module_param(heartbeat, int, 0); module_param(heartbeat, int, 0);
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<heartbeat<2046, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); MODULE_PARM_DESC(heartbeat,
"Watchdog heartbeat in seconds. (1<heartbeat<2046, default="
__MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
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 i6300ESB specific functions * Some i6300ESB specific functions
@@ -114,7 +119,6 @@ static void esb_timer_start(void)
/* Enable or Enable + Lock? */ /* Enable or Enable + Lock? */
val = 0x02 | (nowayout ? 0x01 : 0x00); val = 0x02 | (nowayout ? 0x01 : 0x00);
pci_write_config_byte(esb_pci, ESB_LOCK_REG, val); pci_write_config_byte(esb_pci, ESB_LOCK_REG, val);
} }
@@ -211,10 +215,11 @@ static int esb_open (struct inode *inode, struct file *file)
static int esb_release(struct inode *inode, struct file *file) static int esb_release(struct inode *inode, struct file *file)
{ {
/* Shut off the timer. */ /* Shut off the timer. */
if (esb_expect_close == 42) { if (esb_expect_close == 42)
esb_timer_stop(); esb_timer_stop();
} else { else {
printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); printk(KERN_CRIT PFX
"Unexpected close, not stopping watchdog!\n");
esb_timer_keepalive(); esb_timer_keepalive();
} }
clear_bit(0, &timer_alive); clear_bit(0, &timer_alive);
@@ -250,8 +255,7 @@ static ssize_t esb_write (struct file *file, const char __user *data,
return len; return len;
} }
static int esb_ioctl (struct inode *inode, struct file *file, static long esb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
unsigned int cmd, unsigned long arg)
{ {
int new_options, retval = -EINVAL; int new_options, retval = -EINVAL;
int new_heartbeat; int new_heartbeat;
@@ -295,25 +299,19 @@ static int esb_ioctl (struct inode *inode, struct file *file,
esb_timer_start(); esb_timer_start();
retval = 0; retval = 0;
} }
return retval; return retval;
} }
case WDIOC_SETTIMEOUT: case WDIOC_SETTIMEOUT:
{ {
if (get_user(new_heartbeat, p)) if (get_user(new_heartbeat, p))
return -EFAULT; return -EFAULT;
if (esb_timer_set_heartbeat(new_heartbeat)) if (esb_timer_set_heartbeat(new_heartbeat))
return -EINVAL; return -EINVAL;
esb_timer_keepalive(); esb_timer_keepalive();
/* Fall */ /* Fall */
} }
case WDIOC_GETTIMEOUT: case WDIOC_GETTIMEOUT:
return put_user(heartbeat, p); return put_user(heartbeat, p);
default: default:
return -ENOTTY; return -ENOTTY;
} }
@@ -323,13 +321,13 @@ static int esb_ioctl (struct inode *inode, struct file *file,
* Notify system * Notify system
*/ */
static int esb_notify_sys (struct notifier_block *this, unsigned long code, void *unused) static int esb_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 */ /* Turn the WDT off */
esb_timer_stop(); esb_timer_stop();
} }
return NOTIFY_DONE; return NOTIFY_DONE;
} }
@@ -341,7 +339,7 @@ static const struct file_operations esb_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = esb_write, .write = esb_write,
.ioctl = esb_ioctl, .unlocked_ioctl = esb_ioctl,
.open = esb_open, .open = esb_open,
.release = esb_release, .release = esb_release,
}; };
@@ -378,18 +376,12 @@ static unsigned char __init esb_getdevice (void)
{ {
u8 val1; u8 val1;
unsigned short val2; unsigned short val2;
struct pci_dev *dev = NULL;
/* /*
* Find the PCI device * Find the PCI device
*/ */
for_each_pci_dev(dev) { esb_pci = pci_get_device(PCI_VENDOR_ID_INTEL,
if (pci_match_id(esb_pci_tbl, dev)) { PCI_DEVICE_ID_INTEL_ESB_9, NULL);
esb_pci = dev;
break;
}
}
if (esb_pci) { if (esb_pci) {
if (pci_enable_device(esb_pci)) { if (pci_enable_device(esb_pci)) {
@@ -460,32 +452,32 @@ static int __init watchdog_init (void)
if (!esb_getdevice() || esb_pci == NULL) if (!esb_getdevice() || esb_pci == NULL)
return -ENODEV; return -ENODEV;
/* Check that the heartbeat value is within it's range ; if not reset to the default */ /* Check that the heartbeat value is within it's range;
if not reset to the default */
if (esb_timer_set_heartbeat(heartbeat)) { if (esb_timer_set_heartbeat(heartbeat)) {
esb_timer_set_heartbeat(WATCHDOG_HEARTBEAT); esb_timer_set_heartbeat(WATCHDOG_HEARTBEAT);
printk(KERN_INFO PFX "heartbeat value must be 1<heartbeat<2046, using %d\n", printk(KERN_INFO PFX
"heartbeat value must be 1<heartbeat<2046, using %d\n",
heartbeat); heartbeat);
} }
ret = register_reboot_notifier(&esb_notifier); ret = register_reboot_notifier(&esb_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 err_unmap; goto err_unmap;
} }
ret = misc_register(&esb_miscdev); ret = misc_register(&esb_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 err_notifier; goto err_notifier;
} }
esb_timer_stop(); esb_timer_stop();
printk(KERN_INFO PFX
printk (KERN_INFO PFX "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n", "initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
BASEADDR, heartbeat, nowayout); BASEADDR, heartbeat, nowayout);
return 0; return 0;
err_notifier: err_notifier: