patch-2.3.19 linux/drivers/char/pcwd.c

Next file: linux/drivers/char/pcxx.c
Previous file: linux/drivers/char/joystick/joystick.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.18/linux/drivers/char/pcwd.c linux/drivers/char/pcwd.c
@@ -59,6 +59,7 @@
 #include <linux/watchdog.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/spinlock.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -96,6 +97,7 @@
 
 static int current_readport, revision, temp_panic;
 static int is_open, initial_status, supports_temp, mode_debug;
+static spinlock_t io_lock;
 
 /*
  * PCWD_CHECKCARD
@@ -246,10 +248,12 @@
 		return i ? -EFAULT : 0;
 
 	case WDIOC_GETSTATUS:
+		spin_lock(&io_lock);
 		if (revision == PCWD_REVISION_A) 
-		cdat = inb(current_readport);
+			cdat = inb(current_readport);
 		else
 			cdat = inb(current_readport + 1 );
+		spin_unlock(&io_lock);
 		rv = 0;
 
 		if (revision == PCWD_REVISION_A) 
@@ -312,7 +316,9 @@
 		rv = 0;
 		if ((supports_temp) && (mode_debug == 0)) 
 		{
+			spin_lock(&io_lock);
 			rv = inb(current_readport);
+			spin_unlock(&io_lock);
 			if(put_user(rv, (int*) arg))
 				return -EFAULT;
 		} else if(put_user(rv, (int*) arg))
@@ -327,9 +333,11 @@
 
 			if (rv & WDIOS_DISABLECARD) 
 			{
+				spin_lock(&io_lock);
 				outb_p(0xA5, current_readport + 3);
 				outb_p(0xA5, current_readport + 3);
 				cdat = inb_p(current_readport + 2);
+				spin_unlock(&io_lock);
 				if ((cdat & 0x10) == 0) 
 				{
 					printk("pcwd: Could not disable card.\n");
@@ -341,8 +349,10 @@
 
 			if (rv & WDIOS_ENABLECARD) 
 			{
+				spin_lock(&io_lock);
 				outb_p(0x00, current_readport + 3);
 				cdat = inb_p(current_readport + 2);
+				spin_unlock(&io_lock);
 				if (cdat & 0x10) 
 				{
 					printk("pcwd: Could not enable card.\n");
@@ -391,7 +401,11 @@
                     MOD_INC_USE_COUNT;
                     /*  Enable the port  */
                     if (revision == PCWD_REVISION_C)
-                        outb_p(0x00, current_readport + 3);
+                    {
+                    	spin_lock(&io_lock);
+                    	outb_p(0x00, current_readport + 3);
+                    	spin_unlock(&io_lock);
+                    }
                     is_open = 1;
                     return(0);
                 case TEMP_MINOR:
@@ -405,7 +419,7 @@
 static ssize_t pcwd_read(struct file *file, char *buf, size_t count,
 			 loff_t *ppos)
 {
-	unsigned short c = inb(current_readport);
+	unsigned short c;
 	unsigned char cp;
 
 	/*  Can't seek (pread) on this device  */
@@ -418,6 +432,8 @@
 			 * Convert metric to Fahrenheit, since this was
 			 * the decided 'standard' for this return value.
 			 */
+			
+			c = inb(current_readport);
 			cp = (c * 9 / 5) + 32;
 			if(copy_to_user(buf, &cp, 1))
 				return -EFAULT;
@@ -436,8 +452,10 @@
 #ifndef CONFIG_WATCHDOG_NOWAYOUT
 		/*  Disable the board  */
 		if (revision == PCWD_REVISION_C) {
+			spin_lock(&io_lock);
 			outb_p(0xA5, current_readport + 3);
 			outb_p(0xA5, current_readport + 3);
+			spin_unlock(&io_lock);
 		}
 #endif
 	}
@@ -452,11 +470,15 @@
 
 static inline int get_revision(void)
 {
+	int r = PCWD_REVISION_C;
+	
+	spin_lock(&io_lock);
 	if ((inb(current_readport + 2) == 0xFF) ||
 	    (inb(current_readport + 3) == 0xFF))
-		return(PCWD_REVISION_A);
+		r=PCWD_REVISION_A;
+	spin_unlock(&io_lock);
 
-	return(PCWD_REVISION_C);
+	return r;
 }
 
 static int __init send_command(int cmd)
@@ -584,7 +606,8 @@
 #endif
 {
 	int i, found = 0;
-
+	spin_lock_init(&io_lock);
+	
 	revision = PCWD_REVISION_A;
 
 	printk("pcwd: v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)