Commit d6547378 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

it8712f_wdt: Locking and coding style

Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 670d59c0
...@@ -30,9 +30,8 @@ ...@@ -30,9 +30,8 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <asm/uaccess.h> #include <linux/io.h>
#include <asm/io.h>
#define NAME "it8712f_wdt" #define NAME "it8712f_wdt"
...@@ -50,7 +49,7 @@ static int nowayout = WATCHDOG_NOWAYOUT; ...@@ -50,7 +49,7 @@ static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0); module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close"); 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 unsigned expect_close;
static spinlock_t io_lock; static spinlock_t io_lock;
static unsigned char revision; static unsigned char revision;
...@@ -86,22 +85,19 @@ static unsigned short address; ...@@ -86,22 +85,19 @@ static unsigned short address;
#define WDT_OUT_PWROK 0x10 #define WDT_OUT_PWROK 0x10
#define WDT_OUT_KRST 0x40 #define WDT_OUT_KRST 0x40
static int static int superio_inb(int reg)
superio_inb(int reg)
{ {
outb(reg, REG); outb(reg, REG);
return inb(VAL); return inb(VAL);
} }
static void static void superio_outb(int val, int reg)
superio_outb(int val, int reg)
{ {
outb(reg, REG); outb(reg, REG);
outb(val, VAL); outb(val, VAL);
} }
static int static int superio_inw(int reg)
superio_inw(int reg)
{ {
int val; int val;
outb(reg++, REG); outb(reg++, REG);
...@@ -111,15 +107,13 @@ superio_inw(int reg) ...@@ -111,15 +107,13 @@ superio_inw(int reg)
return val; return val;
} }
static inline void static inline void superio_select(int ldn)
superio_select(int ldn)
{ {
outb(LDN, REG); outb(LDN, REG);
outb(ldn, VAL); outb(ldn, VAL);
} }
static inline void static inline void superio_enter(void)
superio_enter(void)
{ {
spin_lock(&io_lock); spin_lock(&io_lock);
outb(0x87, REG); outb(0x87, REG);
...@@ -128,22 +122,19 @@ superio_enter(void) ...@@ -128,22 +122,19 @@ superio_enter(void)
outb(0x55, REG); outb(0x55, REG);
} }
static inline void static inline void superio_exit(void)
superio_exit(void)
{ {
outb(0x02, REG); outb(0x02, REG);
outb(0x02, VAL); outb(0x02, VAL);
spin_unlock(&io_lock); spin_unlock(&io_lock);
} }
static inline void static inline void it8712f_wdt_ping(void)
it8712f_wdt_ping(void)
{ {
inb(address); inb(address);
} }
static void static void it8712f_wdt_update_margin(void)
it8712f_wdt_update_margin(void)
{ {
int config = WDT_OUT_KRST | WDT_OUT_PWROK; int config = WDT_OUT_KRST | WDT_OUT_PWROK;
int units = margin; int units = margin;
...@@ -165,8 +156,7 @@ it8712f_wdt_update_margin(void) ...@@ -165,8 +156,7 @@ it8712f_wdt_update_margin(void)
superio_outb(units, WDT_TIMEOUT); superio_outb(units, WDT_TIMEOUT);
} }
static int static int it8712f_wdt_get_status(void)
it8712f_wdt_get_status(void)
{ {
if (superio_inb(WDT_CONTROL) & 0x01) if (superio_inb(WDT_CONTROL) & 0x01)
return WDIOF_CARDRESET; return WDIOF_CARDRESET;
...@@ -174,8 +164,7 @@ it8712f_wdt_get_status(void) ...@@ -174,8 +164,7 @@ it8712f_wdt_get_status(void)
return 0; return 0;
} }
static void static void it8712f_wdt_enable(void)
it8712f_wdt_enable(void)
{ {
printk(KERN_DEBUG NAME ": enabling watchdog timer\n"); printk(KERN_DEBUG NAME ": enabling watchdog timer\n");
superio_enter(); superio_enter();
...@@ -190,8 +179,7 @@ it8712f_wdt_enable(void) ...@@ -190,8 +179,7 @@ it8712f_wdt_enable(void)
it8712f_wdt_ping(); it8712f_wdt_ping();
} }
static void static void it8712f_wdt_disable(void)
it8712f_wdt_disable(void)
{ {
printk(KERN_DEBUG NAME ": disabling watchdog timer\n"); printk(KERN_DEBUG NAME ": disabling watchdog timer\n");
...@@ -207,8 +195,7 @@ it8712f_wdt_disable(void) ...@@ -207,8 +195,7 @@ it8712f_wdt_disable(void)
superio_exit(); superio_exit();
} }
static int static int it8712f_wdt_notify(struct notifier_block *this,
it8712f_wdt_notify(struct notifier_block *this,
unsigned long code, void *unused) unsigned long code, void *unused)
{ {
if (code == SYS_HALT || code == SYS_POWER_OFF) if (code == SYS_HALT || code == SYS_POWER_OFF)
...@@ -222,8 +209,7 @@ static struct notifier_block it8712f_wdt_notifier = { ...@@ -222,8 +209,7 @@ static struct notifier_block it8712f_wdt_notifier = {
.notifier_call = it8712f_wdt_notify, .notifier_call = it8712f_wdt_notify,
}; };
static ssize_t static ssize_t it8712f_wdt_write(struct file *file, const char __user *data,
it8712f_wdt_write(struct file *file, const char __user *data,
size_t len, loff_t *ppos) size_t len, loff_t *ppos)
{ {
/* check for a magic close character */ /* check for a magic close character */
...@@ -245,9 +231,8 @@ it8712f_wdt_write(struct file *file, const char __user *data, ...@@ -245,9 +231,8 @@ it8712f_wdt_write(struct file *file, const char __user *data,
return len; return len;
} }
static int static long it8712f_wdt_ioctl(struct file *file, unsigned int cmd,
it8712f_wdt_ioctl(struct inode *inode, struct file *file, unsigned long arg)
unsigned int cmd, unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int __user *p = argp; int __user *p = argp;
...@@ -302,19 +287,16 @@ it8712f_wdt_ioctl(struct inode *inode, struct file *file, ...@@ -302,19 +287,16 @@ it8712f_wdt_ioctl(struct inode *inode, struct file *file,
} }
} }
static int static int it8712f_wdt_open(struct inode *inode, struct file *file)
it8712f_wdt_open(struct inode *inode, struct file *file)
{ {
/* only allow one at a time */ /* only allow one at a time */
if (down_trylock(&it8712f_wdt_sem)) if (test_and_set_bit(0, &wdt_open))
return -EBUSY; return -EBUSY;
it8712f_wdt_enable(); it8712f_wdt_enable();
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
static int static int it8712f_wdt_release(struct inode *inode, struct file *file)
it8712f_wdt_release(struct inode *inode, struct file *file)
{ {
if (expect_close != 42) { if (expect_close != 42) {
printk(KERN_WARNING NAME printk(KERN_WARNING NAME
...@@ -324,7 +306,7 @@ it8712f_wdt_release(struct inode *inode, struct file *file) ...@@ -324,7 +306,7 @@ it8712f_wdt_release(struct inode *inode, struct file *file)
it8712f_wdt_disable(); it8712f_wdt_disable();
} }
expect_close = 0; expect_close = 0;
up(&it8712f_wdt_sem); clear_bit(0, &wdt_open);
return 0; return 0;
} }
...@@ -333,7 +315,7 @@ static const struct file_operations it8712f_wdt_fops = { ...@@ -333,7 +315,7 @@ static const struct file_operations it8712f_wdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = it8712f_wdt_write, .write = it8712f_wdt_write,
.ioctl = it8712f_wdt_ioctl, .unlocked_ioctl = it8712f_wdt_ioctl,
.open = it8712f_wdt_open, .open = it8712f_wdt_open,
.release = it8712f_wdt_release, .release = it8712f_wdt_release,
}; };
...@@ -344,8 +326,7 @@ static struct miscdevice it8712f_wdt_miscdev = { ...@@ -344,8 +326,7 @@ static struct miscdevice it8712f_wdt_miscdev = {
.fops = &it8712f_wdt_fops, .fops = &it8712f_wdt_fops,
}; };
static int __init static int __init it8712f_wdt_find(unsigned short *address)
it8712f_wdt_find(unsigned short *address)
{ {
int err = -ENODEV; int err = -ENODEV;
int chip_type; int chip_type;
...@@ -387,8 +368,7 @@ it8712f_wdt_find(unsigned short *address) ...@@ -387,8 +368,7 @@ it8712f_wdt_find(unsigned short *address)
return err; return err;
} }
static int __init static int __init it8712f_wdt_init(void)
it8712f_wdt_init(void)
{ {
int err = 0; int err = 0;
...@@ -404,8 +384,6 @@ it8712f_wdt_init(void) ...@@ -404,8 +384,6 @@ it8712f_wdt_init(void)
it8712f_wdt_disable(); it8712f_wdt_disable();
sema_init(&it8712f_wdt_sem, 1);
err = register_reboot_notifier(&it8712f_wdt_notifier); err = register_reboot_notifier(&it8712f_wdt_notifier);
if (err) { if (err) {
printk(KERN_ERR NAME ": unable to register reboot notifier\n"); printk(KERN_ERR NAME ": unable to register reboot notifier\n");
...@@ -430,8 +408,7 @@ it8712f_wdt_init(void) ...@@ -430,8 +408,7 @@ it8712f_wdt_init(void)
return err; return err;
} }
static void __exit static void __exit it8712f_wdt_exit(void)
it8712f_wdt_exit(void)
{ {
misc_deregister(&it8712f_wdt_miscdev); misc_deregister(&it8712f_wdt_miscdev);
unregister_reboot_notifier(&it8712f_wdt_notifier); unregister_reboot_notifier(&it8712f_wdt_notifier);
......
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