]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[WATCHDOG 43/57] sc520_wdt: Clean up and switch to unlocked_ioctl
authorAlan Cox <alan@redhat.com>
Mon, 19 May 2008 13:08:44 +0000 (14:08 +0100)
committerWim Van Sebroeck <wim@iguana.be>
Sat, 21 Jun 2008 15:30:57 +0000 (15:30 +0000)
Review and switch to unlocked_ioctl

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
drivers/watchdog/sc520_wdt.c

index 2847324a2be2ec22f5fab63dec124d185266d671..525555a8779caa96c5636db2abbbd41a9b8c71d1 100644 (file)
@@ -64,9 +64,9 @@
 #include <linux/reboot.h>
 #include <linux/init.h>
 #include <linux/jiffies.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 
-#include <asm/io.h>
-#include <asm/uaccess.h>
 #include <asm/system.h>
 
 #define OUR_NAME "sc520_wdt"
  */
 
 #define WATCHDOG_TIMEOUT 30            /* 30 sec default timeout */
-static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
+/* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
+static int timeout = WATCHDOG_TIMEOUT;
 module_param(timeout, int, 0);
-MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
+MODULE_PARM_DESC(timeout,
+       "Watchdog timeout in seconds. (1 <= timeout <= 3600, default="
+                               __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
 
 static int nowayout = WATCHDOG_NOWAYOUT;
 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) ")");
 
 /*
  * AMD Elan SC520 - Watchdog Timer Registers
@@ -136,8 +141,7 @@ static void wdt_timer_ping(unsigned long data)
        /* If we got a heartbeat pulse within the WDT_US_INTERVAL
         * we agree to ping the WDT
         */
-       if(time_before(jiffies, next_heartbeat))
-       {
+       if (time_before(jiffies, next_heartbeat)) {
                /* Ping the WDT */
                spin_lock(&wdt_spinlock);
                writew(0xAAAA, wdtmrctl);
@@ -146,9 +150,9 @@ static void wdt_timer_ping(unsigned long data)
 
                /* Re-set the timer interval */
                mod_timer(&timer, jiffies + WDT_INTERVAL);
-       } else {
-               printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
-       }
+       } else
+               printk(KERN_WARNING PFX
+                       "Heartbeat lost! Will not ping the watchdog\n");
 }
 
 /*
@@ -162,7 +166,7 @@ static void wdt_config(int writeval)
 
        /* buy some time (ping) */
        spin_lock_irqsave(&wdt_spinlock, flags);
-       dummy=readw(wdtmrctl);  /* ensure write synchronization */
+       dummy = readw(wdtmrctl);        /* ensure write synchronization */
        writew(0xAAAA, wdtmrctl);
        writew(0x5555, wdtmrctl);
        /* unlock WDT = make WDT configuration register writable one time */
@@ -219,10 +223,11 @@ static int wdt_set_heartbeat(int t)
  *     /dev/watchdog handling
  */
 
-static ssize_t fop_write(struct file * file, const char __user * buf, size_t count, loff_t * ppos)
+static ssize_t fop_write(struct file *file, const char __user *buf,
+                                               size_t count, loff_t *ppos)
 {
        /* See if we got the magic character 'V' and reload the timer */
-       if(count) {
+       if (count) {
                if (!nowayout) {
                        size_t ofs;
 
@@ -231,25 +236,26 @@ static ssize_t fop_write(struct file * file, const char __user * buf, size_t cou
                        wdt_expect_close = 0;
 
                        /* now scan */
-                       for(ofs = 0; ofs != count; ofs++) {
+                       for (ofs = 0; ofs != count; ofs++) {
                                char c;
                                if (get_user(c, buf + ofs))
                                        return -EFAULT;
-                               if(c == 'V')
+                               if (c == 'V')
                                        wdt_expect_close = 42;
                        }
                }
 
-               /* Well, anyhow someone wrote to us, we should return that favour */
+               /* Well, anyhow someone wrote to us, we should
+                  return that favour */
                wdt_keepalive();
        }
        return count;
 }
 
-static int fop_open(struct inode * inode, struct file * file)
+static int fop_open(struct inode *inode, struct file *file)
 {
        /* Just in case we're already talking to someone... */
-       if(test_and_set_bit(0, &wdt_is_open))
+       if (test_and_set_bit(0, &wdt_is_open))
                return -EBUSY;
        if (nowayout)
                __module_get(THIS_MODULE);
@@ -259,12 +265,13 @@ static int fop_open(struct inode * inode, struct file * file)
        return nonseekable_open(inode, file);
 }
 
-static int fop_close(struct inode * inode, struct file * file)
+static int fop_close(struct inode *inode, struct file *file)
 {
-       if(wdt_expect_close == 42) {
+       if (wdt_expect_close == 42)
                wdt_turnoff();
-       } else {
-               printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
+       else {
+               printk(KERN_CRIT PFX
+                       "Unexpected close, not stopping watchdog!\n");
                wdt_keepalive();
        }
        clear_bit(0, &wdt_is_open);
@@ -272,63 +279,63 @@ static int fop_close(struct inode * inode, struct file * file)
        return 0;
 }
 
-static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-       unsigned long arg)
+static int fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
        int __user *p = argp;
-       static struct watchdog_info ident = {
-               .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
+       static const struct watchdog_info ident = {
+               .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT
+                                                       | WDIOF_MAGICCLOSE,
                .firmware_version = 1,
                .identity = "SC520",
        };
 
-       switch(cmd)
+       switch (cmd)
        {
-               default:
-                       return -ENOTTY;
-               case WDIOC_GETSUPPORT:
-                       return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
-               case WDIOC_GETSTATUS:
-               case WDIOC_GETBOOTSTATUS:
-                       return put_user(0, p);
-               case WDIOC_KEEPALIVE:
-                       wdt_keepalive();
-                       return 0;
-               case WDIOC_SETOPTIONS:
-               {
-                       int new_options, retval = -EINVAL;
-
-                       if(get_user(new_options, p))
-                               return -EFAULT;
-
-                       if(new_options & WDIOS_DISABLECARD) {
-                               wdt_turnoff();
-                               retval = 0;
-                       }
+       default:
+               return -ENOTTY;
+       case WDIOC_GETSUPPORT:
+               return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
+       case WDIOC_GETSTATUS:
+       case WDIOC_GETBOOTSTATUS:
+               return put_user(0, p);
+       case WDIOC_KEEPALIVE:
+               wdt_keepalive();
+               return 0;
+       case WDIOC_SETOPTIONS:
+       {
+               int new_options, retval = -EINVAL;
 
-                       if(new_options & WDIOS_ENABLECARD) {
-                               wdt_startup();
-                               retval = 0;
-                       }
+               if (get_user(new_options, p))
+                       return -EFAULT;
+
+               if (new_options & WDIOS_DISABLECARD) {
+                       wdt_turnoff();
+                       retval = 0;
+               }
 
-                       return retval;
+               if (new_options & WDIOS_ENABLECARD) {
+                       wdt_startup();
+                       retval = 0;
                }
-               case WDIOC_SETTIMEOUT:
-               {
-                       int new_timeout;
 
-                       if(get_user(new_timeout, p))
-                               return -EFAULT;
+               return retval;
+       }
+       case WDIOC_SETTIMEOUT:
+       {
+               int new_timeout;
 
-                       if(wdt_set_heartbeat(new_timeout))
-                               return -EINVAL;
+               if (get_user(new_timeout, p))
+                       return -EFAULT;
 
-                       wdt_keepalive();
-                       /* Fall through */
-               }
-               case WDIOC_GETTIMEOUT:
-                       return put_user(timeout, p);
+               if (wdt_set_heartbeat(new_timeout))
+                       return -EINVAL;
+
+               wdt_keepalive();
+               /* Fall through */
+       }
+       case WDIOC_GETTIMEOUT:
+               return put_user(timeout, p);
        }
 }
 
@@ -354,7 +361,7 @@ static struct miscdevice wdt_miscdev = {
 static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
        void *unused)
 {
-       if(code==SYS_DOWN || code==SYS_HALT)
+       if (code == SYS_DOWN || code == SYS_HALT)
                wdt_turnoff();
        return NOTIFY_DONE;
 }
@@ -383,11 +390,13 @@ static int __init sc520_wdt_init(void)
 {
        int rc = -EBUSY;
 
-       /* Check that the timeout value is within it's range ; if not reset to the default */
+       /* Check that the timeout value is within it's range ;
+          if not reset to the default */
        if (wdt_set_heartbeat(timeout)) {
                wdt_set_heartbeat(WATCHDOG_TIMEOUT);
-               printk(KERN_INFO PFX "timeout value must be 1<=timeout<=3600, using %d\n",
-                       WATCHDOG_TIMEOUT);
+               printk(KERN_INFO PFX
+                   "timeout value must be 1 <= timeout <= 3600, using %d\n",
+                                                       WATCHDOG_TIMEOUT);
        }
 
        wdtmrctl = ioremap((unsigned long)(MMCR_BASE + OFFS_WDTMRCTL), 2);
@@ -399,20 +408,22 @@ static int __init sc520_wdt_init(void)
 
        rc = register_reboot_notifier(&wdt_notifier);
        if (rc) {
-               printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
-                       rc);
+               printk(KERN_ERR PFX
+                       "cannot register reboot notifier (err=%d)\n", rc);
                goto err_out_ioremap;
        }
 
        rc = misc_register(&wdt_miscdev);
        if (rc) {
-               printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
-                       WATCHDOG_MINOR, rc);
+               printk(KERN_ERR PFX
+                       "cannot register miscdev on minor=%d (err=%d)\n",
+                                                       WATCHDOG_MINOR, rc);
                goto err_out_notifier;
        }
 
-       printk(KERN_INFO PFX "WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n",
-               timeout,nowayout);
+       printk(KERN_INFO PFX
+          "WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n",
+                                                       timeout, nowayout);
 
        return 0;