Commit 70b814ec authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck

[WATCHDOG 45/57] shwdt: coding style, cleanup, switch to unlocked_ioctl

Review and switch to unlocked_ioctl
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 9b748ed0
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/watchdog.h> #include <linux/watchdog.h>
#define PFX "shwdt: " #define PFX "shwdt: "
...@@ -72,6 +72,7 @@ static struct watchdog_info sh_wdt_info; ...@@ -72,6 +72,7 @@ static struct watchdog_info sh_wdt_info;
static char shwdt_expect_close; static char shwdt_expect_close;
static DEFINE_TIMER(timer, sh_wdt_ping, 0, 0); static DEFINE_TIMER(timer, sh_wdt_ping, 0, 0);
static unsigned long next_heartbeat; static unsigned long next_heartbeat;
static DEFINE_SPINLOCK(shwdt_lock);
#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */ #define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
...@@ -86,6 +87,9 @@ static int nowayout = WATCHDOG_NOWAYOUT; ...@@ -86,6 +87,9 @@ static int nowayout = WATCHDOG_NOWAYOUT;
static void sh_wdt_start(void) static void sh_wdt_start(void)
{ {
__u8 csr; __u8 csr;
unsigned long flags;
spin_lock_irqsave(&wdt_lock, flags);
next_heartbeat = jiffies + (heartbeat * HZ); next_heartbeat = jiffies + (heartbeat * HZ);
mod_timer(&timer, next_ping_period(clock_division_ratio)); mod_timer(&timer, next_ping_period(clock_division_ratio));
...@@ -123,6 +127,7 @@ static void sh_wdt_start(void) ...@@ -123,6 +127,7 @@ static void sh_wdt_start(void)
csr &= ~RSTCSR_RSTS; csr &= ~RSTCSR_RSTS;
sh_wdt_write_rstcsr(csr); sh_wdt_write_rstcsr(csr);
#endif #endif
spin_unlock_irqrestore(&wdt_lock, flags);
} }
/** /**
...@@ -132,12 +137,16 @@ static void sh_wdt_start(void) ...@@ -132,12 +137,16 @@ static void sh_wdt_start(void)
static void sh_wdt_stop(void) static void sh_wdt_stop(void)
{ {
__u8 csr; __u8 csr;
unsigned long flags;
spin_lock_irqsave(&wdt_lock, flags);
del_timer(&timer); del_timer(&timer);
csr = sh_wdt_read_csr(); csr = sh_wdt_read_csr();
csr &= ~WTCSR_TME; csr &= ~WTCSR_TME;
sh_wdt_write_csr(csr); sh_wdt_write_csr(csr);
spin_unlock_irqrestore(&wdt_lock, flags);
} }
/** /**
...@@ -146,7 +155,11 @@ static void sh_wdt_stop(void) ...@@ -146,7 +155,11 @@ static void sh_wdt_stop(void)
*/ */
static inline void sh_wdt_keepalive(void) static inline void sh_wdt_keepalive(void)
{ {
unsigned long flags;
spin_lock_irqsave(&wdt_lock, flags);
next_heartbeat = jiffies + (heartbeat * HZ); next_heartbeat = jiffies + (heartbeat * HZ);
spin_unlock_irqrestore(&wdt_lock, flags);
} }
/** /**
...@@ -155,10 +168,14 @@ static inline void sh_wdt_keepalive(void) ...@@ -155,10 +168,14 @@ static inline void sh_wdt_keepalive(void)
*/ */
static int sh_wdt_set_heartbeat(int t) static int sh_wdt_set_heartbeat(int t)
{ {
if (unlikely((t < 1) || (t > 3600))) /* arbitrary upper limit */ unsigned long flags;
if (unlikely(t < 1 || t > 3600)) /* arbitrary upper limit */
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&wdt_lock, flags);
heartbeat = t; heartbeat = t;
spin_unlock_irqrestore(&wdt_lock, flags);
return 0; return 0;
} }
...@@ -170,6 +187,9 @@ static int sh_wdt_set_heartbeat(int t) ...@@ -170,6 +187,9 @@ static int sh_wdt_set_heartbeat(int t)
*/ */
static void sh_wdt_ping(unsigned long data) static void sh_wdt_ping(unsigned long data)
{ {
unsigned long flags;
spin_lock_irqsave(&wdt_lock, flags);
if (time_before(jiffies, next_heartbeat)) { if (time_before(jiffies, next_heartbeat)) {
__u8 csr; __u8 csr;
...@@ -183,6 +203,7 @@ static void sh_wdt_ping(unsigned long data) ...@@ -183,6 +203,7 @@ static void sh_wdt_ping(unsigned long data)
} else } else
printk(KERN_WARNING PFX "Heartbeat lost! Will not ping " printk(KERN_WARNING PFX "Heartbeat lost! Will not ping "
"the watchdog\n"); "the watchdog\n");
spin_unlock_irqrestore(&wdt_lock, flags);
} }
/** /**
...@@ -310,7 +331,6 @@ static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -310,7 +331,6 @@ static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma)
/** /**
* sh_wdt_ioctl - Query Device * sh_wdt_ioctl - Query Device
* @inode: inode of device
* @file: file handle of device * @file: file handle of device
* @cmd: watchdog command * @cmd: watchdog command
* @arg: argument * @arg: argument
...@@ -318,53 +338,51 @@ static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -318,53 +338,51 @@ static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma)
* Query basic information from the device or ping it, as outlined by the * Query basic information from the device or ping it, as outlined by the
* watchdog API. * watchdog API.
*/ */
static int sh_wdt_ioctl(struct inode *inode, struct file *file, static long sh_wdt_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
int new_heartbeat; int new_heartbeat;
int options, retval = -EINVAL; int options, retval = -EINVAL;
switch (cmd) { switch (cmd) {
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
return copy_to_user((struct watchdog_info *)arg, return copy_to_user((struct watchdog_info *)arg,
&sh_wdt_info, &sh_wdt_info, sizeof(sh_wdt_info)) ? -EFAULT : 0;
sizeof(sh_wdt_info)) ? -EFAULT : 0; case WDIOC_GETSTATUS:
case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS:
case WDIOC_GETBOOTSTATUS: return put_user(0, (int *)arg);
return put_user(0, (int *)arg); case WDIOC_KEEPALIVE:
case WDIOC_KEEPALIVE: sh_wdt_keepalive();
sh_wdt_keepalive(); return 0;
return 0; case WDIOC_SETTIMEOUT:
case WDIOC_SETTIMEOUT: if (get_user(new_heartbeat, (int *)arg))
if (get_user(new_heartbeat, (int *)arg)) return -EFAULT;
return -EFAULT;
if (sh_wdt_set_heartbeat(new_heartbeat))
return -EINVAL;
sh_wdt_keepalive();
/* Fall */
case WDIOC_GETTIMEOUT:
return put_user(heartbeat, (int *)arg);
case WDIOC_SETOPTIONS:
if (get_user(options, (int *)arg))
return -EFAULT;
if (options & WDIOS_DISABLECARD) {
sh_wdt_stop();
retval = 0;
}
if (options & WDIOS_ENABLECARD) { if (sh_wdt_set_heartbeat(new_heartbeat))
sh_wdt_start(); return -EINVAL;
retval = 0;
}
return retval; sh_wdt_keepalive();
default: /* Fall */
return -ENOTTY; case WDIOC_GETTIMEOUT:
} return put_user(heartbeat, (int *)arg);
case WDIOC_SETOPTIONS:
if (get_user(options, (int *)arg))
return -EFAULT;
if (options & WDIOS_DISABLECARD) {
sh_wdt_stop();
retval = 0;
}
if (options & WDIOS_ENABLECARD) {
sh_wdt_start();
retval = 0;
}
return retval;
default:
return -ENOTTY;
}
return 0; return 0;
} }
...@@ -390,13 +408,13 @@ static const struct file_operations sh_wdt_fops = { ...@@ -390,13 +408,13 @@ static const struct file_operations sh_wdt_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.write = sh_wdt_write, .write = sh_wdt_write,
.ioctl = sh_wdt_ioctl, .unlocked_ioctl = sh_wdt_ioctl,
.open = sh_wdt_open, .open = sh_wdt_open,
.release = sh_wdt_close, .release = sh_wdt_close,
.mmap = sh_wdt_mmap, .mmap = sh_wdt_mmap,
}; };
static struct watchdog_info sh_wdt_info = { static const struct watchdog_info sh_wdt_info = {
.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
WDIOF_MAGICCLOSE, WDIOF_MAGICCLOSE,
.firmware_version = 1, .firmware_version = 1,
...@@ -422,30 +440,33 @@ static int __init sh_wdt_init(void) ...@@ -422,30 +440,33 @@ static int __init sh_wdt_init(void)
{ {
int rc; int rc;
if ((clock_division_ratio < 0x5) || (clock_division_ratio > 0x7)) { if (clock_division_ratio < 0x5 || clock_division_ratio > 0x7) {
clock_division_ratio = WTCSR_CKS_4096; clock_division_ratio = WTCSR_CKS_4096;
printk(KERN_INFO PFX "clock_division_ratio value must " printk(KERN_INFO PFX
"be 0x5<=x<=0x7, using %d\n", clock_division_ratio); "clock_division_ratio value must be 0x5<=x<=0x7, using %d\n",
clock_division_ratio);
} }
rc = sh_wdt_set_heartbeat(heartbeat); rc = sh_wdt_set_heartbeat(heartbeat);
if (unlikely(rc)) { if (unlikely(rc)) {
heartbeat = WATCHDOG_HEARTBEAT; heartbeat = WATCHDOG_HEARTBEAT;
printk(KERN_INFO PFX "heartbeat value must " printk(KERN_INFO PFX
"be 1<=x<=3600, using %d\n", heartbeat); "heartbeat value must be 1<=x<=3600, using %d\n",
heartbeat);
} }
rc = register_reboot_notifier(&sh_wdt_notifier); rc = register_reboot_notifier(&sh_wdt_notifier);
if (unlikely(rc)) { if (unlikely(rc)) {
printk(KERN_ERR PFX "Can't register reboot notifier (err=%d)\n", printk(KERN_ERR PFX
rc); "Can't register reboot notifier (err=%d)\n", rc);
return rc; return rc;
} }
rc = misc_register(&sh_wdt_miscdev); rc = misc_register(&sh_wdt_miscdev);
if (unlikely(rc)) { if (unlikely(rc)) {
printk(KERN_ERR PFX "Can't register miscdev on " printk(KERN_ERR PFX
"minor=%d (err=%d)\n", sh_wdt_miscdev.minor, rc); "Can't register miscdev on minor=%d (err=%d)\n",
sh_wdt_miscdev.minor, rc);
unregister_reboot_notifier(&sh_wdt_notifier); unregister_reboot_notifier(&sh_wdt_notifier);
return rc; return rc;
} }
...@@ -476,10 +497,14 @@ module_param(clock_division_ratio, int, 0); ...@@ -476,10 +497,14 @@ module_param(clock_division_ratio, int, 0);
MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). (default=" __MODULE_STRING(clock_division_ratio) ")"); MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). (default=" __MODULE_STRING(clock_division_ratio) ")");
module_param(heartbeat, int, 0); module_param(heartbeat, int, 0);
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<=heartbeat<=3600, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); MODULE_PARM_DESC(heartbeat,
"Watchdog heartbeat in seconds. (1 <= heartbeat <= 3600, default="
__MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
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) ")");
module_init(sh_wdt_init); module_init(sh_wdt_init);
module_exit(sh_wdt_exit); module_exit(sh_wdt_exit);
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