From 8c30fef8814eb5784fd659d33dfb0c1df3bfebaa Mon Sep 17 00:00:00 2001
From: Wim Van Sebroeck <wim@iguana.be>
Date: Sat, 3 Jan 2004 00:06:45 +0100
Subject: [PATCH] [WATCHDOG] 2.6.0-rc1 _is_open.patch

Make _is_open code consistent for all watchdog-drivers
---
 drivers/char/watchdog/ib700wdt.c | 11 ++++-------
 drivers/char/watchdog/machzwd.c  | 12 ++++--------
 drivers/char/watchdog/mixcomwd.c |  2 +-
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c
index 2141b57e506a..3e029e165a7c 100644
--- a/drivers/char/watchdog/ib700wdt.c
+++ b/drivers/char/watchdog/ib700wdt.c
@@ -48,7 +48,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
-static int ibwdt_is_open;
+static unsigned long ibwdt_is_open;
 static spinlock_t ibwdt_lock;
 static char expect_close;
 
@@ -184,9 +184,7 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 	  break;
 
 	case WDIOC_GETSTATUS:
-	  if (copy_to_user((int *)arg, &ibwdt_is_open,  sizeof(int)))
-	    return -EFAULT;
-	  break;
+	  return put_user(0, (int *) arg);
 
 	case WDIOC_KEEPALIVE:
 	  ibwdt_ping();
@@ -218,7 +216,7 @@ static int
 ibwdt_open(struct inode *inode, struct file *file)
 {
 	spin_lock(&ibwdt_lock);
-	if (ibwdt_is_open) {
+	if (test_and_set_bit(0, &ibwdt_is_open)) {
 		spin_unlock(&ibwdt_lock);
 		return -EBUSY;
 	}
@@ -226,7 +224,6 @@ ibwdt_open(struct inode *inode, struct file *file)
 		__module_get(THIS_MODULE);
 
 	/* Activate */
-	ibwdt_is_open = 1;
 	ibwdt_ping();
 	spin_unlock(&ibwdt_lock);
 	return 0;
@@ -241,7 +238,7 @@ ibwdt_close(struct inode *inode, struct file *file)
 	else
 		printk(KERN_CRIT PFX "WDT device closed unexpectedly.  WDT will not stop!\n");
 
-	ibwdt_is_open = 0;
+	clear_bit(0, &ibwdt_is_open);
 	expect_close = 0;
 	spin_unlock(&ibwdt_lock);
 	return 0;
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 511277ea509f..aa3202dc69e1 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -130,7 +130,7 @@ module_param(action, int, 0);
 MODULE_PARM_DESC(action, "after watchdog resets, generate: 0 = RESET(*)  1 = SMI  2 = NMI  3 = SCI");
 
 static int zf_action = GEN_RESET;
-static int zf_is_open = 0;
+static unsigned long zf_is_open;
 static char zf_expect_close;
 static spinlock_t zf_lock;
 static spinlock_t zf_port_lock;
@@ -359,9 +359,7 @@ static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 			break;
 	  
 		case WDIOC_GETSTATUS:
-			if (copy_to_user((int *)arg, &zf_is_open, sizeof(int)))
-				return -EFAULT;
-			break;
+			return put_user(0, (int *) arg);
 
 		case WDIOC_KEEPALIVE:
 			zf_ping(0);
@@ -377,7 +375,7 @@ static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 static int zf_open(struct inode *inode, struct file *file)
 {
 	spin_lock(&zf_lock);
-	if(zf_is_open){
+	if(test_and_set_bit(0, &zf_is_open)) {
 		spin_unlock(&zf_lock);
 		return -EBUSY;
 	}
@@ -385,8 +383,6 @@ static int zf_open(struct inode *inode, struct file *file)
 	if (nowayout)
 		__module_get(THIS_MODULE);
 
-	zf_is_open = 1;
-
 	spin_unlock(&zf_lock);
 
 	zf_timer_on();
@@ -404,7 +400,7 @@ static int zf_close(struct inode *inode, struct file *file)
 	}
 		
 	spin_lock(&zf_lock);
-	zf_is_open = 0;
+	clear_bit(0, &zf_is_open);
 	spin_unlock(&zf_lock);
 
 	zf_expect_close = 0;
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index 45be5ebd8c61..8993c11a46c5 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -55,7 +55,7 @@ static int mixcomwd_ioports[] = { 0x180, 0x280, 0x380, 0x000 };
 #define FLASHCOM_WATCHDOG_OFFSET 0x4
 #define FLASHCOM_ID 0x18
 
-static long mixcomwd_opened; /* long req'd for setbit --RR */
+static unsigned long mixcomwd_opened; /* long req'd for setbit --RR */
 
 static int watchdog_port;
 static int mixcomwd_timer_alive;
-- 
2.30.9