*             fairly useless proc entry.
  * 990610      removed said useless proc code for the merge <alan>
  * 000403      Removed last traces of proc code. <davej>
- * 011214      Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
+ * 011214      Added nowayout module option to override
+ *             CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
  *              Added timeout module option to override default
  */
 
 /*
  *     A bells and whistles driver is available from http://www.pcwd.de/
- *     More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
+ *     More info available at http://www.berkprod.com/ or
+ *     http://www.pcwatchdog.com/
  */
 
 #include <linux/module.h>      /* For module specific items */
 #include <linux/isa.h>         /* For isa devices */
 #include <linux/ioport.h>      /* For io-port access */
 #include <linux/spinlock.h>    /* For spin_lock/spin_unlock/... */
-
-#include <asm/uaccess.h>       /* For copy_to_user/put_user/... */
-#include <asm/io.h>            /* For inb/outb/... */
+#include <linux/uaccess.h>     /* For copy_to_user/put_user/... */
+#include <linux/io.h>          /* For inb/outb/... */
 
 /* Module and version information */
 #define WATCHDOG_VERSION "1.20"
 #define WD_REVC_WTRP           0x01    /* Watchdog Trip status */
 #define WD_REVC_HRBT           0x02    /* Watchdog Heartbeat */
 #define WD_REVC_TTRP           0x04    /* Temperature Trip status */
-#define WD_REVC_RL2A           0x08    /* Relay 2 activated by on-board processor */
+#define WD_REVC_RL2A           0x08    /* Relay 2 activated by
+                                                       on-board processor */
 #define WD_REVC_RL1A           0x10    /* Relay 1 active */
 #define WD_REVC_R2DS           0x40    /* Relay 2 disable */
 #define WD_REVC_RLY2           0x80    /* Relay 2 activated? */
 /* Port 2 : Control Status #2 */
 #define WD_WDIS                        0x10    /* Watchdog Disabled */
 #define WD_ENTP                        0x20    /* Watchdog Enable Temperature Trip */
-#define WD_SSEL                        0x40    /* Watchdog Switch Select (1:SW1 <-> 0:SW2) */
+#define WD_SSEL                        0x40    /* Watchdog Switch Select
+                                                       (1:SW1 <-> 0:SW2) */
 #define WD_WCMD                        0x80    /* Watchdog Command Mode */
 
 /* max. time we give an ISA watchdog card to process a command */
 static atomic_t open_allowed = ATOMIC_INIT(1);
 static char expect_close;
 static int temp_panic;
-static struct {                                /* this is private data for each ISA-PC watchdog card */
+
+/* this is private data for each ISA-PC watchdog card */
+static struct {
        char fw_ver_str[6];             /* The cards firmware version */
        int revision;                   /* The card's revision */
-       int supports_temp;              /* Wether or not the card has a temperature device */
-       int command_mode;               /* Wether or not the card is in command mode */
+       int supports_temp;              /* Whether or not the card has
+                                               a temperature device */
+       int command_mode;               /* Whether or not the card is in
+                                               command mode */
        int boot_status;                /* The card's boot status */
        int io_addr;                    /* The cards I/O address */
        spinlock_t io_lock;             /* the lock for io operations */
 #define DEBUG  2       /* print fancy stuff too */
 static int debug = QUIET;
 module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
+MODULE_PARM_DESC(debug,
+               "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
 
-#define WATCHDOG_HEARTBEAT 0           /* default heartbeat = delay-time from dip-switches */
+/* default heartbeat = delay-time from dip-switches */
+#define WATCHDOG_HEARTBEAT 0
 static int heartbeat = WATCHDOG_HEARTBEAT;
 module_param(heartbeat, int, 0);
-MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
+MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2 <= heartbeat <= 7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
 
 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) ")");
 
 /*
  *     Internal functions
                if (port0 == last_port0)
                        break;  /* Data is stable */
 
-               udelay (250);
+               udelay(250);
        }
 
        if (debug >= DEBUG)
 
 static int set_command_mode(void)
 {
-       int i, found=0, count=0;
+       int i, found = 0, count = 0;
 
        /* Set the card into command mode */
        spin_lock(&pcwd_private.io_lock);
                ten = send_isa_command(CMD_ISA_VERSION_TENTH);
                hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
                minor = send_isa_command(CMD_ISA_VERSION_MINOR);
-               sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
+               sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c",
+                                       one, ten, hund, minor);
        }
        unset_command_mode();
 
 
 static inline int pcwd_get_option_switches(void)
 {
-       int option_switches=0;
+       int option_switches = 0;
 
        if (set_command_mode()) {
                /* Get switch settings */
 
        /* Get some extra info from the hardware (in command/debug/diag mode) */
        if (pcwd_private.revision == PCWD_REVISION_A)
-               printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
+               printk(KERN_INFO PFX
+                       "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n",
+                                                       pcwd_private.io_addr);
        else if (pcwd_private.revision == PCWD_REVISION_C) {
                pcwd_get_firmware();
                printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
                printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
 
        if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
-               printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
-               printk(KERN_EMERG PFX "CPU Overheat\n");
+               printk(KERN_EMERG PFX
+                       "Card senses a CPU Overheat. Panicking!\n");
+               printk(KERN_EMERG PFX
+                       "CPU Overheat\n");
        }
 
        if (pcwd_private.boot_status == 0)
-               printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
+               printk(KERN_INFO PFX
+                       "No previous trip detected - Cold boot or reset\n");
 }
 
 static void pcwd_timer_ping(unsigned long data)
 
        /* If we got a heartbeat pulse within the WDT_INTERVAL
         * we agree to ping the WDT */
-       if(time_before(jiffies, pcwd_private.next_heartbeat)) {
+       if (time_before(jiffies, pcwd_private.next_heartbeat)) {
                /* Ping the watchdog */
                spin_lock(&pcwd_private.io_lock);
                if (pcwd_private.revision == PCWD_REVISION_A) {
-                       /*  Rev A cards are reset by setting the WD_WDRST bit in register 1 */
+                       /*  Rev A cards are reset by setting the
+                           WD_WDRST bit in register 1 */
                        wdrst_stat = inb_p(pcwd_private.io_addr);
                        wdrst_stat &= 0x0F;
                        wdrst_stat |= WD_WDRST;
 
                spin_unlock(&pcwd_private.io_lock);
        } else {
-               printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
+               printk(KERN_WARNING PFX
+                       "Heartbeat lost! Will not ping the watchdog\n");
        }
 }
 
 
 static int pcwd_set_heartbeat(int t)
 {
-       if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
+       if (t < 2 || t > 7200) /* arbitrary upper limit */
                return -EINVAL;
 
        heartbeat = t;
 {
        int control_status;
 
-       *status=0;
+       *status = 0;
        spin_lock(&pcwd_private.io_lock);
        if (pcwd_private.revision == PCWD_REVISION_A)
                /* Rev A cards return status information from
                if (control_status & WD_T110) {
                        *status |= WDIOF_OVERHEAT;
                        if (temp_panic) {
-                               printk(KERN_INFO PFX "Temperature overheat trip!\n");
+                               printk(KERN_INFO PFX
+                                       "Temperature overheat trip!\n");
                                kernel_power_off();
-                               /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
                        }
                }
        } else {
                if (control_status & WD_REVC_TTRP) {
                        *status |= WDIOF_OVERHEAT;
                        if (temp_panic) {
-                               printk(KERN_INFO PFX "Temperature overheat trip!\n");
+                               printk(KERN_INFO PFX
+                                       "Temperature overheat trip!\n");
                                kernel_power_off();
-                               /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
                        }
                }
        }
                spin_lock(&pcwd_private.io_lock);
 
                if (debug >= VERBOSE)
-                       printk(KERN_INFO PFX "clearing watchdog trip status\n");
+                       printk(KERN_INFO PFX
+                                       "clearing watchdog trip status\n");
 
                control_status = inb_p(pcwd_private.io_addr + 1);
 
                if (debug >= DEBUG) {
-                       printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
+                       printk(KERN_DEBUG PFX "status was: 0x%02x\n",
+                               control_status);
                        printk(KERN_DEBUG PFX "sending: 0x%02x\n",
                                (control_status & WD_REVC_R2DS));
                }
 
                /* clear reset status & Keep Relay 2 disable state as it is */
-               outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
+               outb_p((control_status & WD_REVC_R2DS),
+                                               pcwd_private.io_addr + 1);
 
                spin_unlock(&pcwd_private.io_lock);
        }
  *     /dev/watchdog handling
  */
 
-static int pcwd_ioctl(struct inode *inode, struct file *file,
-                     unsigned int cmd, unsigned long arg)
+static long pcwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        int rv;
        int status;
                .identity =             "PCWD",
        };
 
-       switch(cmd) {
+       switch (cmd) {
        default:
                return -ENOTTY;
 
        case WDIOC_GETSUPPORT:
-               if(copy_to_user(argp, &ident, sizeof(ident)))
+               if (copy_to_user(argp, &ident, sizeof(ident)))
                        return -EFAULT;
                return 0;
 
                return put_user(temperature, argp);
 
        case WDIOC_SETOPTIONS:
-               if (pcwd_private.revision == PCWD_REVISION_C)
-               {
-                       if(copy_from_user(&rv, argp, sizeof(int)))
+               if (pcwd_private.revision == PCWD_REVISION_C) {
+                       if (get_user(rv, argp))
                                return -EFAULT;
 
-                       if (rv & WDIOS_DISABLECARD)
-                       {
-                               return pcwd_stop();
+                       if (rv & WDIOS_DISABLECARD) {
+                               status = pcwd_stop();
+                               if (status < 0)
+                                       return status;
                        }
-
-                       if (rv & WDIOS_ENABLECARD)
-                       {
-                               return pcwd_start();
+                       if (rv & WDIOS_ENABLECARD) {
+                               status = pcwd_start();
+                               if (status < 0)
+                                       return status;
                        }
-
                        if (rv & WDIOS_TEMPPANIC)
-                       {
                                temp_panic = 1;
-                       }
                }
                return -EINVAL;
 
 
 static int pcwd_open(struct inode *inode, struct file *file)
 {
-       if (!atomic_dec_and_test(&open_allowed) ) {
-               if (debug >= VERBOSE)
-                       printk(KERN_ERR PFX "Attempt to open already opened device.\n");
-               atomic_inc( &open_allowed );
+       if (test_and_set_bit(0, &open_allowed))
                return -EBUSY;
-       }
-
        if (nowayout)
                __module_get(THIS_MODULE);
-
        /* Activate */
        pcwd_start();
        pcwd_keepalive();
 
 static int pcwd_close(struct inode *inode, struct file *file)
 {
-       if (expect_close == 42) {
+       if (expect_close == 42)
                pcwd_stop();
-       } else {
-               printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
+       else {
+               printk(KERN_CRIT PFX
+                       "Unexpected close, not stopping watchdog!\n");
                pcwd_keepalive();
        }
        expect_close = 0;
-       atomic_inc( &open_allowed );
+       clear_bit(0, &open_allowed);
        return 0;
 }
 
        .owner          = THIS_MODULE,
        .llseek         = no_llseek,
        .write          = pcwd_write,
-       .ioctl          = pcwd_ioctl,
+       .unlocked_ioctl = pcwd_ioctl,
        .open           = pcwd_open,
        .release        = pcwd_close,
 };
         * presumes a floating bus reads as 0xff. */
        if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
            (inb(pcwd_private.io_addr + 3) == 0xFF))
-               r=PCWD_REVISION_A;
+               r = PCWD_REVISION_A;
        spin_unlock(&pcwd_private.io_lock);
 
        return r;
  */
 static int __devinit pcwd_isa_match(struct device *dev, unsigned int id)
 {
-       int base_addr=pcwd_ioports[id];
+       int base_addr = pcwd_ioports[id];
        int port0, last_port0;  /* Reg 0, in case it's REV A */
        int port1, last_port1;  /* Register 1 for REV C cards */
        int i;
                printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n",
                        id);
 
-       if (!request_region (base_addr, 4, "PCWD")) {
+       if (!request_region(base_addr, 4, "PCWD")) {
                printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
                return 0;
        }
                        }
                }
        }
-       release_region (base_addr, 4);
+       release_region(base_addr, 4);
 
        return retval;
 }
 
        cards_found++;
        if (cards_found == 1)
-               printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
+               printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n",
+                                                               WD_VER);
 
        if (cards_found > 1) {
                printk(KERN_ERR PFX "This driver only supports 1 device\n");
        /* Check card's revision */
        pcwd_private.revision = get_revision();
 
-       if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
+       if (!request_region(pcwd_private.io_addr,
+               (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
                printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
                        pcwd_private.io_addr);
-               ret=-EIO;
+               ret = -EIO;
                goto error_request_region;
        }
 
        if (heartbeat == 0)
                heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
 
-       /* Check that the heartbeat value is within it's range ; if not reset to the default */
+       /* Check that the heartbeat value is within it's range;
+          if not reset to the default */
        if (pcwd_set_heartbeat(heartbeat)) {
                pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
-               printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
-                       WATCHDOG_HEARTBEAT);
+               printk(KERN_INFO PFX
+                 "heartbeat value must be 2 <= heartbeat <= 7200, using %d\n",
+                                                       WATCHDOG_HEARTBEAT);
        }
 
        if (pcwd_private.supports_temp) {
                ret = misc_register(&temp_miscdev);
                if (ret) {
-                       printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
-                               TEMP_MINOR, ret);
+                       printk(KERN_ERR PFX
+                           "cannot register miscdev on minor=%d (err=%d)\n",
+                                                       TEMP_MINOR, ret);
                        goto error_misc_register_temp;
                }
        }
 
        ret = misc_register(&pcwd_miscdev);
        if (ret) {
-               printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
-                       WATCHDOG_MINOR, ret);
+               printk(KERN_ERR PFX
+                       "cannot register miscdev on minor=%d (err=%d)\n",
+                                       WATCHDOG_MINOR, ret);
                goto error_misc_register_watchdog;
        }
 
        if (pcwd_private.supports_temp)
                misc_deregister(&temp_miscdev);
 error_misc_register_temp:
-       release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
+       release_region(pcwd_private.io_addr,
+                       (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
 error_request_region:
        pcwd_private.io_addr = 0x0000;
        cards_found--;
        misc_deregister(&pcwd_miscdev);
        if (pcwd_private.supports_temp)
                misc_deregister(&temp_miscdev);
-       release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
+       release_region(pcwd_private.io_addr,
+                       (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
        pcwd_private.io_addr = 0x0000;
        cards_found--;