[WATCHDOG 47/57] softdog: clean up, coding style and switch to 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
598467938d
commit
f92d3749d7
@@ -47,19 +47,22 @@
|
|||||||
#include <linux/reboot.h>
|
#include <linux/reboot.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/jiffies.h>
|
#include <linux/jiffies.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
#include <asm/uaccess.h>
|
|
||||||
|
|
||||||
#define PFX "SoftDog: "
|
#define PFX "SoftDog: "
|
||||||
|
|
||||||
#define TIMER_MARGIN 60 /* Default is 60 seconds */
|
#define TIMER_MARGIN 60 /* Default is 60 seconds */
|
||||||
static int soft_margin = TIMER_MARGIN; /* in seconds */
|
static int soft_margin = TIMER_MARGIN; /* in seconds */
|
||||||
module_param(soft_margin, int, 0);
|
module_param(soft_margin, int, 0);
|
||||||
MODULE_PARM_DESC(soft_margin, "Watchdog soft_margin in seconds. (0<soft_margin<65536, default=" __MODULE_STRING(TIMER_MARGIN) ")");
|
MODULE_PARM_DESC(soft_margin,
|
||||||
|
"Watchdog soft_margin in seconds. (0 < soft_margin < 65536, default="
|
||||||
|
__MODULE_STRING(TIMER_MARGIN) ")");
|
||||||
|
|
||||||
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) ")");
|
||||||
|
|
||||||
#ifdef ONLY_TESTING
|
#ifdef ONLY_TESTING
|
||||||
static int soft_noboot = 1;
|
static int soft_noboot = 1;
|
||||||
@@ -93,8 +96,7 @@ static void watchdog_fire(unsigned long data)
|
|||||||
|
|
||||||
if (soft_noboot)
|
if (soft_noboot)
|
||||||
printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n");
|
printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
printk(KERN_CRIT PFX "Initiating system reboot.\n");
|
printk(KERN_CRIT PFX "Initiating system reboot.\n");
|
||||||
emergency_restart();
|
emergency_restart();
|
||||||
printk(KERN_CRIT PFX "Reboot didn't ?????\n");
|
printk(KERN_CRIT PFX "Reboot didn't ?????\n");
|
||||||
@@ -153,7 +155,8 @@ static int softdog_release(struct inode *inode, struct file *file)
|
|||||||
softdog_stop();
|
softdog_stop();
|
||||||
module_put(THIS_MODULE);
|
module_put(THIS_MODULE);
|
||||||
} else {
|
} else {
|
||||||
printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
|
printk(KERN_CRIT PFX
|
||||||
|
"Unexpected close, not stopping watchdog!\n");
|
||||||
set_bit(0, &orphan_timer);
|
set_bit(0, &orphan_timer);
|
||||||
softdog_keepalive();
|
softdog_keepalive();
|
||||||
}
|
}
|
||||||
@@ -162,12 +165,13 @@ static int softdog_release(struct inode *inode, struct file *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t softdog_write(struct file *file, const char __user *data, size_t len, loff_t *ppos)
|
static ssize_t softdog_write(struct file *file, const char __user *data,
|
||||||
|
size_t len, loff_t *ppos)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Refresh the timer.
|
* Refresh the timer.
|
||||||
*/
|
*/
|
||||||
if(len) {
|
if (len) {
|
||||||
if (!nowayout) {
|
if (!nowayout) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@@ -188,13 +192,13 @@ static ssize_t softdog_write(struct file *file, const char __user *data, size_t
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int softdog_ioctl(struct inode *inode, struct file *file,
|
static long softdog_ioctl(struct file *file, unsigned int cmd,
|
||||||
unsigned int cmd, unsigned long arg)
|
unsigned long arg)
|
||||||
{
|
{
|
||||||
void __user *argp = (void __user *)arg;
|
void __user *argp = (void __user *)arg;
|
||||||
int __user *p = argp;
|
int __user *p = argp;
|
||||||
int new_margin;
|
int new_margin;
|
||||||
static struct watchdog_info ident = {
|
static const struct watchdog_info ident = {
|
||||||
.options = WDIOF_SETTIMEOUT |
|
.options = WDIOF_SETTIMEOUT |
|
||||||
WDIOF_KEEPALIVEPING |
|
WDIOF_KEEPALIVEPING |
|
||||||
WDIOF_MAGICCLOSE,
|
WDIOF_MAGICCLOSE,
|
||||||
@@ -202,26 +206,25 @@ static int softdog_ioctl(struct inode *inode, struct file *file,
|
|||||||
.identity = "Software Watchdog",
|
.identity = "Software Watchdog",
|
||||||
};
|
};
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
default:
|
default:
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
case WDIOC_GETSUPPORT:
|
case WDIOC_GETSUPPORT:
|
||||||
return copy_to_user(argp, &ident,
|
return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
|
||||||
sizeof(ident)) ? -EFAULT : 0;
|
case WDIOC_GETSTATUS:
|
||||||
case WDIOC_GETSTATUS:
|
case WDIOC_GETBOOTSTATUS:
|
||||||
case WDIOC_GETBOOTSTATUS:
|
return put_user(0, p);
|
||||||
return put_user(0, p);
|
case WDIOC_KEEPALIVE:
|
||||||
case WDIOC_KEEPALIVE:
|
softdog_keepalive();
|
||||||
softdog_keepalive();
|
return 0;
|
||||||
return 0;
|
case WDIOC_SETTIMEOUT:
|
||||||
case WDIOC_SETTIMEOUT:
|
if (get_user(new_margin, p))
|
||||||
if (get_user(new_margin, p))
|
return -EFAULT;
|
||||||
return -EFAULT;
|
if (softdog_set_heartbeat(new_margin))
|
||||||
if (softdog_set_heartbeat(new_margin))
|
return -EINVAL;
|
||||||
return -EINVAL;
|
softdog_keepalive();
|
||||||
softdog_keepalive();
|
/* Fall */
|
||||||
/* Fall */
|
case WDIOC_GETTIMEOUT:
|
||||||
case WDIOC_GETTIMEOUT:
|
return put_user(soft_margin, p);
|
||||||
return put_user(soft_margin, p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,10 +235,9 @@ static int softdog_ioctl(struct inode *inode, struct file *file,
|
|||||||
static int softdog_notify_sys(struct notifier_block *this, unsigned long code,
|
static int softdog_notify_sys(struct notifier_block *this, unsigned long code,
|
||||||
void *unused)
|
void *unused)
|
||||||
{
|
{
|
||||||
if(code==SYS_DOWN || code==SYS_HALT) {
|
if (code == SYS_DOWN || code == SYS_HALT)
|
||||||
/* Turn the WDT off */
|
/* Turn the WDT off */
|
||||||
softdog_stop();
|
softdog_stop();
|
||||||
}
|
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +249,7 @@ static const struct file_operations softdog_fops = {
|
|||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.llseek = no_llseek,
|
.llseek = no_llseek,
|
||||||
.write = softdog_write,
|
.write = softdog_write,
|
||||||
.ioctl = softdog_ioctl,
|
.unlocked_ioctl = softdog_ioctl,
|
||||||
.open = softdog_open,
|
.open = softdog_open,
|
||||||
.release = softdog_release,
|
.release = softdog_release,
|
||||||
};
|
};
|
||||||
@@ -268,24 +270,27 @@ static int __init watchdog_init(void)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check that the soft_margin value is within it's range ; if not reset to the default */
|
/* Check that the soft_margin value is within it's range;
|
||||||
|
if not reset to the default */
|
||||||
if (softdog_set_heartbeat(soft_margin)) {
|
if (softdog_set_heartbeat(soft_margin)) {
|
||||||
softdog_set_heartbeat(TIMER_MARGIN);
|
softdog_set_heartbeat(TIMER_MARGIN);
|
||||||
printk(KERN_INFO PFX "soft_margin value must be 0<soft_margin<65536, using %d\n",
|
printk(KERN_INFO PFX
|
||||||
|
"soft_margin must be 0 < soft_margin < 65536, using %d\n",
|
||||||
TIMER_MARGIN);
|
TIMER_MARGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = register_reboot_notifier(&softdog_notifier);
|
ret = register_reboot_notifier(&softdog_notifier);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
|
printk(KERN_ERR PFX
|
||||||
ret);
|
"cannot register reboot notifier (err=%d)\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = misc_register(&softdog_miscdev);
|
ret = misc_register(&softdog_miscdev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
|
printk(KERN_ERR PFX
|
||||||
WATCHDOG_MINOR, ret);
|
"cannot register miscdev on minor=%d (err=%d)\n",
|
||||||
|
WATCHDOG_MINOR, ret);
|
||||||
unregister_reboot_notifier(&softdog_notifier);
|
unregister_reboot_notifier(&softdog_notifier);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user