[WATCHDOG 25/57] mixcomwd: coding style locking, 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
325ea4d3a8
commit
3930964532
@@ -29,7 +29,8 @@
|
|||||||
* - support for one more type board
|
* - support for one more type board
|
||||||
*
|
*
|
||||||
* Version 0.5 (2001/12/14) Matt Domsch <Matt_Domsch@dell.com>
|
* Version 0.5 (2001/12/14) Matt Domsch <Matt_Domsch@dell.com>
|
||||||
* - added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
|
* - added nowayout module option to override
|
||||||
|
* CONFIG_WATCHDOG_NOWAYOUT
|
||||||
*
|
*
|
||||||
* Version 0.6 (2002/04/12): Rob Radez <rob@osinvestor.com>
|
* Version 0.6 (2002/04/12): Rob Radez <rob@osinvestor.com>
|
||||||
* - make mixcomwd_opened unsigned,
|
* - make mixcomwd_opened unsigned,
|
||||||
@@ -53,8 +54,8 @@
|
|||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/jiffies.h>
|
#include <linux/jiffies.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
#include <asm/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
#include <asm/io.h>
|
#include <linux/io.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have two types of cards that can be probed:
|
* We have two types of cards that can be probed:
|
||||||
@@ -108,7 +109,9 @@ static char expect_close;
|
|||||||
|
|
||||||
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 mixcomwd_ping(void)
|
static void mixcomwd_ping(void)
|
||||||
{
|
{
|
||||||
@@ -119,7 +122,6 @@ static void mixcomwd_ping(void)
|
|||||||
static void mixcomwd_timerfun(unsigned long d)
|
static void mixcomwd_timerfun(unsigned long d)
|
||||||
{
|
{
|
||||||
mixcomwd_ping();
|
mixcomwd_ping();
|
||||||
|
|
||||||
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
|
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,19 +131,19 @@ static void mixcomwd_timerfun(unsigned long d)
|
|||||||
|
|
||||||
static int mixcomwd_open(struct inode *inode, struct file *file)
|
static int mixcomwd_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
if(test_and_set_bit(0,&mixcomwd_opened)) {
|
if (test_and_set_bit(0, &mixcomwd_opened))
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
|
||||||
mixcomwd_ping();
|
mixcomwd_ping();
|
||||||
|
|
||||||
if (nowayout) {
|
if (nowayout)
|
||||||
/*
|
/*
|
||||||
* fops_get() code via open() has already done
|
* fops_get() code via open() has already done
|
||||||
* a try_module_get() so it is safe to do the
|
* a try_module_get() so it is safe to do the
|
||||||
* __module_get().
|
* __module_get().
|
||||||
*/
|
*/
|
||||||
__module_get(THIS_MODULE);
|
__module_get(THIS_MODULE);
|
||||||
} else {
|
else {
|
||||||
if (mixcomwd_timer_alive) {
|
if (mixcomwd_timer_alive) {
|
||||||
del_timer(&mixcomwd_timer);
|
del_timer(&mixcomwd_timer);
|
||||||
mixcomwd_timer_alive = 0;
|
mixcomwd_timer_alive = 0;
|
||||||
@@ -154,14 +156,15 @@ static int mixcomwd_release(struct inode *inode, struct file *file)
|
|||||||
{
|
{
|
||||||
if (expect_close == 42) {
|
if (expect_close == 42) {
|
||||||
if (mixcomwd_timer_alive) {
|
if (mixcomwd_timer_alive) {
|
||||||
printk(KERN_ERR PFX "release called while internal timer alive");
|
printk(KERN_ERR PFX
|
||||||
|
"release called while internal timer alive");
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
mixcomwd_timer_alive = 1;
|
mixcomwd_timer_alive = 1;
|
||||||
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
|
mod_timer(&mixcomwd_timer, jiffies + 5 * HZ);
|
||||||
} 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");
|
||||||
|
|
||||||
clear_bit(0, &mixcomwd_opened);
|
clear_bit(0, &mixcomwd_opened);
|
||||||
expect_close = 0;
|
expect_close = 0;
|
||||||
@@ -169,10 +172,10 @@ static int mixcomwd_release(struct inode *inode, struct file *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ssize_t mixcomwd_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
|
static ssize_t mixcomwd_write(struct file *file, const char __user *data,
|
||||||
{
|
size_t len, loff_t *ppos)
|
||||||
if(len)
|
|
||||||
{
|
{
|
||||||
|
if (len) {
|
||||||
if (!nowayout) {
|
if (!nowayout) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@@ -192,7 +195,7 @@ static ssize_t mixcomwd_write(struct file *file, const char __user *data, size_t
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mixcomwd_ioctl(struct inode *inode, struct file *file,
|
static long mixcomwd_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;
|
||||||
@@ -204,26 +207,17 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file,
|
|||||||
.identity = "MixCOM watchdog",
|
.identity = "MixCOM watchdog",
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case WDIOC_GETSTATUS:
|
case WDIOC_GETSTATUS:
|
||||||
status = mixcomwd_opened;
|
status = mixcomwd_opened;
|
||||||
if (!nowayout) {
|
if (!nowayout)
|
||||||
status |= mixcomwd_timer_alive;
|
status |= mixcomwd_timer_alive;
|
||||||
}
|
return put_user(status, p);
|
||||||
if (copy_to_user(p, &status, sizeof(int))) {
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WDIOC_GETBOOTSTATUS:
|
case WDIOC_GETBOOTSTATUS:
|
||||||
if (copy_to_user(p, &status, sizeof(int))) {
|
return put_user(0, p);
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
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_KEEPALIVE:
|
case WDIOC_KEEPALIVE:
|
||||||
mixcomwd_ping();
|
mixcomwd_ping();
|
||||||
@@ -238,7 +232,7 @@ static const struct file_operations mixcomwd_fops = {
|
|||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.llseek = no_llseek,
|
.llseek = no_llseek,
|
||||||
.write = mixcomwd_write,
|
.write = mixcomwd_write,
|
||||||
.ioctl = mixcomwd_ioctl,
|
.unlocked_ioctl = mixcomwd_ioctl,
|
||||||
.open = mixcomwd_open,
|
.open = mixcomwd_open,
|
||||||
.release = mixcomwd_release,
|
.release = mixcomwd_release,
|
||||||
};
|
};
|
||||||
@@ -253,9 +247,8 @@ static int __init checkcard(int port, int card_id)
|
|||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
if (!request_region(port, 1, "MixCOM watchdog")) {
|
if (!request_region(port, 1, "MixCOM watchdog"))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
id = inb_p(port);
|
id = inb_p(port);
|
||||||
if (card_id == MIXCOM_ID)
|
if (card_id == MIXCOM_ID)
|
||||||
@@ -270,9 +263,7 @@ static int __init checkcard(int port, int card_id)
|
|||||||
|
|
||||||
static int __init mixcomwd_init(void)
|
static int __init mixcomwd_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i, ret, found = 0;
|
||||||
int ret;
|
|
||||||
int found=0;
|
|
||||||
|
|
||||||
for (i = 0; !found && mixcomwd_io_info[i].ioport != 0; i++) {
|
for (i = 0; !found && mixcomwd_io_info[i].ioport != 0; i++) {
|
||||||
if (checkcard(mixcomwd_io_info[i].ioport,
|
if (checkcard(mixcomwd_io_info[i].ioport,
|
||||||
@@ -283,19 +274,21 @@ static int __init mixcomwd_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
printk(KERN_ERR PFX "No card detected, or port not available.\n");
|
printk(KERN_ERR PFX
|
||||||
|
"No card detected, or port not available.\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = misc_register(&mixcomwd_miscdev);
|
ret = misc_register(&mixcomwd_miscdev);
|
||||||
if (ret)
|
if (ret) {
|
||||||
{
|
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",
|
||||||
WATCHDOG_MINOR, ret);
|
WATCHDOG_MINOR, ret);
|
||||||
goto error_misc_register_watchdog;
|
goto error_misc_register_watchdog;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO "MixCOM watchdog driver v%s, watchdog port at 0x%3x\n",
|
printk(KERN_INFO
|
||||||
|
"MixCOM watchdog driver v%s, watchdog port at 0x%3x\n",
|
||||||
VERSION, watchdog_port);
|
VERSION, watchdog_port);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user