Skip to content

Commit

Permalink
[WATCHDOG 17/57] it8712f: unlocked_ioctl
Browse files Browse the repository at this point in the history
Review and switch to unlocked_ioctl

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  • Loading branch information
Alan Cox authored and Wim Van Sebroeck committed May 27, 2008
1 parent 02e3814 commit 30abcec
Showing 1 changed file with 27 additions and 50 deletions.
77 changes: 27 additions & 50 deletions drivers/watchdog/it8712f_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
#include <linux/fs.h>
#include <linux/pci.h>
#include <linux/spinlock.h>

#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/uaccess.h>
#include <linux/io.h>

#define NAME "it8712f_wdt"

Expand All @@ -50,7 +49,7 @@ static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");

static struct semaphore it8712f_wdt_sem;
static unsigned long wdt_open;
static unsigned expect_close;
static spinlock_t io_lock;
static unsigned char revision;
Expand Down Expand Up @@ -86,22 +85,19 @@ static unsigned short address;
#define WDT_OUT_PWROK 0x10
#define WDT_OUT_KRST 0x40

static int
superio_inb(int reg)
static int superio_inb(int reg)
{
outb(reg, REG);
return inb(VAL);
}

static void
superio_outb(int val, int reg)
static void superio_outb(int val, int reg)
{
outb(reg, REG);
outb(val, VAL);
}

static int
superio_inw(int reg)
static int superio_inw(int reg)
{
int val;
outb(reg++, REG);
Expand All @@ -111,15 +107,13 @@ superio_inw(int reg)
return val;
}

static inline void
superio_select(int ldn)
static inline void superio_select(int ldn)
{
outb(LDN, REG);
outb(ldn, VAL);
}

static inline void
superio_enter(void)
static inline void superio_enter(void)
{
spin_lock(&io_lock);
outb(0x87, REG);
Expand All @@ -128,22 +122,19 @@ superio_enter(void)
outb(0x55, REG);
}

static inline void
superio_exit(void)
static inline void superio_exit(void)
{
outb(0x02, REG);
outb(0x02, VAL);
spin_unlock(&io_lock);
}

static inline void
it8712f_wdt_ping(void)
static inline void it8712f_wdt_ping(void)
{
inb(address);
}

static void
it8712f_wdt_update_margin(void)
static void it8712f_wdt_update_margin(void)
{
int config = WDT_OUT_KRST | WDT_OUT_PWROK;
int units = margin;
Expand All @@ -165,17 +156,15 @@ it8712f_wdt_update_margin(void)
superio_outb(units, WDT_TIMEOUT);
}

static int
it8712f_wdt_get_status(void)
static int it8712f_wdt_get_status(void)
{
if (superio_inb(WDT_CONTROL) & 0x01)
return WDIOF_CARDRESET;
else
return 0;
}

static void
it8712f_wdt_enable(void)
static void it8712f_wdt_enable(void)
{
printk(KERN_DEBUG NAME ": enabling watchdog timer\n");
superio_enter();
Expand All @@ -190,8 +179,7 @@ it8712f_wdt_enable(void)
it8712f_wdt_ping();
}

static void
it8712f_wdt_disable(void)
static void it8712f_wdt_disable(void)
{
printk(KERN_DEBUG NAME ": disabling watchdog timer\n");

Expand All @@ -207,8 +195,7 @@ it8712f_wdt_disable(void)
superio_exit();
}

static int
it8712f_wdt_notify(struct notifier_block *this,
static int it8712f_wdt_notify(struct notifier_block *this,
unsigned long code, void *unused)
{
if (code == SYS_HALT || code == SYS_POWER_OFF)
Expand All @@ -222,9 +209,8 @@ static struct notifier_block it8712f_wdt_notifier = {
.notifier_call = it8712f_wdt_notify,
};

static ssize_t
it8712f_wdt_write(struct file *file, const char __user *data,
size_t len, loff_t *ppos)
static ssize_t it8712f_wdt_write(struct file *file, const char __user *data,
size_t len, loff_t *ppos)
{
/* check for a magic close character */
if (len) {
Expand All @@ -245,9 +231,8 @@ it8712f_wdt_write(struct file *file, const char __user *data,
return len;
}

static int
it8712f_wdt_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
void __user *argp = (void __user *)arg;
int __user *p = argp;
Expand Down Expand Up @@ -302,19 +287,16 @@ it8712f_wdt_ioctl(struct inode *inode, struct file *file,
}
}

static int
it8712f_wdt_open(struct inode *inode, struct file *file)
static int it8712f_wdt_open(struct inode *inode, struct file *file)
{
/* only allow one at a time */
if (down_trylock(&it8712f_wdt_sem))
if (test_and_set_bit(0, &wdt_open))
return -EBUSY;
it8712f_wdt_enable();

return nonseekable_open(inode, file);
}

static int
it8712f_wdt_release(struct inode *inode, struct file *file)
static int it8712f_wdt_release(struct inode *inode, struct file *file)
{
if (expect_close != 42) {
printk(KERN_WARNING NAME
Expand All @@ -324,7 +306,7 @@ it8712f_wdt_release(struct inode *inode, struct file *file)
it8712f_wdt_disable();
}
expect_close = 0;
up(&it8712f_wdt_sem);
clear_bit(0, &wdt_open);

return 0;
}
Expand All @@ -333,7 +315,7 @@ static const struct file_operations it8712f_wdt_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.write = it8712f_wdt_write,
.ioctl = it8712f_wdt_ioctl,
.unlocked_ioctl = it8712f_wdt_ioctl,
.open = it8712f_wdt_open,
.release = it8712f_wdt_release,
};
Expand All @@ -344,8 +326,7 @@ static struct miscdevice it8712f_wdt_miscdev = {
.fops = &it8712f_wdt_fops,
};

static int __init
it8712f_wdt_find(unsigned short *address)
static int __init it8712f_wdt_find(unsigned short *address)
{
int err = -ENODEV;
int chip_type;
Expand Down Expand Up @@ -387,8 +368,7 @@ it8712f_wdt_find(unsigned short *address)
return err;
}

static int __init
it8712f_wdt_init(void)
static int __init it8712f_wdt_init(void)
{
int err = 0;

Expand All @@ -404,8 +384,6 @@ it8712f_wdt_init(void)

it8712f_wdt_disable();

sema_init(&it8712f_wdt_sem, 1);

err = register_reboot_notifier(&it8712f_wdt_notifier);
if (err) {
printk(KERN_ERR NAME ": unable to register reboot notifier\n");
Expand All @@ -430,8 +408,7 @@ it8712f_wdt_init(void)
return err;
}

static void __exit
it8712f_wdt_exit(void)
static void __exit it8712f_wdt_exit(void)
{
misc_deregister(&it8712f_wdt_miscdev);
unregister_reboot_notifier(&it8712f_wdt_notifier);
Expand Down

0 comments on commit 30abcec

Please sign in to comment.