Resent-Date: Mon, 7 Dec 1998 11:25:57 +0100 (MET)
To: linux-m68k@lists.linux-m68k.org
Subject: Fixing timeout handling
X-Yow: UH-OH!!  I put on ``GREAT HEAD-ON TRAIN COLLISIONS of the 50's''
 by mistake!!!
From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Date: 07 Dec 1998 11:25:51 +0100
Resent-From: linux-m68k@phil.uni-sb.de

I've looked a bit through the m68k specific drivers and fixed the timeout
handling to use the macros from <linux/timer.h>, in order to correctly
handle the jiffies wraparound.

Andreas.

----------------------------------------------------------------------
--- linux/arch/m68k/amiga/pcmcia.c.~1~	Mon Aug 10 18:21:17 1998
+++ linux/arch/m68k/amiga/pcmcia.c	Sun Dec  6 13:17:13 1998
@@ -14,6 +14,7 @@
 
 #include <linux/types.h>
 #include <linux/sched.h>
+#include <linux/timer.h>
 #include <asm/amigayle.h>
 #include <asm/amipcmcia.h>
 
@@ -26,7 +27,7 @@
 	unsigned char b;
 
 	gayle_reset = 0x00;
-	while (jiffies - reset_start_time < 1*HZ/100);
+	while (time_before(jiffies, reset_start_time + 1*HZ/100));
 	b = gayle_reset;
 }
 
--- linux/arch/m68k/atari/atakeyb.c.~1~	Mon Aug  3 20:04:41 1998
+++ linux/arch/m68k/atari/atakeyb.c	Sun Dec  6 13:17:51 1998
@@ -825,7 +825,7 @@
     /* wait for a period of inactivity (here: 0.25s), then assume the IKBD's
      * self-test is finished */
     self_test_last_rcv = jiffies;
-    while( jiffies < self_test_last_rcv + HZ/4 )
+    while (time_before(jiffies, self_test_last_rcv + HZ/4))
 	barrier();
     /* if not incremented: no 0xf1 received */
     if (ikbd_self_test == 1)
--- linux/drivers/block/acsi.c.~1~	Fri Nov 13 18:03:56 1998
+++ linux/drivers/block/acsi.c	Sun Dec  6 12:13:19 1998
@@ -252,17 +252,8 @@
 static char				*CurrentBuffer;
 
 
-#define SET_TIMER()							\
-	do {								\
-		del_timer( &acsi_timer );				\
-		acsi_timer.expires = jiffies + ACSI_TIMEOUT;		\
-		add_timer( &acsi_timer );				\
-	} while(0)
-
-#define CLEAR_TIMER()							\
-	do {								\
-		del_timer( &acsi_timer );				\
-	} while(0)
+#define SET_TIMER()	mod_timer(&acsi_timer, jiffies + ACSI_TIMEOUT)
+#define CLEAR_TIMER()	del_timer(&acsi_timer)
 
 static unsigned long	STramMask;
 #define STRAM_ADDR(a)	(((a) & STramMask) == 0)
@@ -424,8 +415,8 @@
 
 {
 	if (INT_LEVEL < 6) {
-		unsigned long maxjif;
-		for( maxjif = jiffies + timeout; jiffies < maxjif; )
+		unsigned long maxjif = jiffies + timeout;
+		while (time_before(jiffies, maxjif))
 			if (!(mfp.par_dt_reg & 0x20)) return( 1 );
 	}
 	else {
@@ -441,8 +432,8 @@
 
 {
 	if (INT_LEVEL < 6) {
-		unsigned long maxjif;
-		for( maxjif = jiffies + timeout; jiffies < maxjif; )
+		unsigned long maxjif = jiffies + timeout;
+		while (time_before(jiffies, maxjif))
 			if (mfp.par_dt_reg & 0x20) return( 1 );
 	}
 	else {
--- linux/drivers/block/acsi_slm.c.~1~	Mon Aug 31 18:04:04 1998
+++ linux/drivers/block/acsi_slm.c	Sun Dec  6 12:14:39 1998
@@ -101,17 +101,8 @@
 		cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5;	\
 	} while(0)
 
-#define	START_TIMER(to)							\
-    do {										\
-        del_timer( &slm_timer );				\
-        slm_timer.expires = jiffies + (to);			\
-        add_timer( &slm_timer );				\
-	} while(0)
-
-#define	STOP_TIMER()							\
-    do {										\
-        del_timer( &slm_timer );				\
-	} while(0)
+#define	START_TIMER(to)	mod_timer(&slm_timer, jiffies + (to))
+#define	STOP_TIMER()	del_timer(&slm_timer)
 
 
 static char slmreqsense_cmd[6] = { 0x03, 0, 0, 0, 0, 0 };
--- linux/drivers/block/ataflop.c.~2~	Sat Nov  7 17:28:55 1998
+++ linux/drivers/block/ataflop.c	Sun Dec  6 11:59:42 1998
@@ -1309,7 +1309,7 @@
 	NeedSeek = 0;
 
 	if ((timer_active & (1 << FLOPPY_TIMER)) &&
-	    timer_table[FLOPPY_TIMER].expires < jiffies + 5)
+	    time_before(timer_table[FLOPPY_TIMER].expires, jiffies + 5))
 		/* If the check for a disk change is done too early after this
 		 * last seek command, the WP bit still reads wrong :-((
 		 */
@@ -1826,10 +1826,10 @@
 	FDC_WRITE (FDCREG_TRACK, 0xff00);
 	FDC_WRITE( FDCREG_CMD, FDCCMD_RESTORE | FDCCMDADD_H | FDCSTEP_6 );
 
-	for( ok = 0, timeout = jiffies + 2*HZ+HZ/2; jiffies < timeout; ) {
+	timeout = jiffies + 2*HZ+HZ/2;
+	while (time_before(jiffies, timeout))
 		if (!(mfp.par_dt_reg & 0x20))
 			break;
-	}
 
 	status = FDC_READ( FDCREG_STATUS );
 	ok = (status & FDCSTAT_TR00) != 0;
--- linux/drivers/char/atari_SCC.c.~1~	Wed Jun 10 17:58:52 1998
+++ linux/drivers/char/atari_SCC.c	Sun Dec  6 12:17:31 1998
@@ -1847,7 +1847,7 @@
 	timeout = jiffies + 50;
 	restore_flags(flags);
 	while( !(SCCread( SPCOND_STATUS_REG ) & SCSR_ALL_SENT) ) {
-		if (jiffies > timeout) break;
+		if (time_after(jiffies, timeout)) break;
 	}
 	save_flags(flags);
 	cli();
--- linux/drivers/char/dn_keyb.c.~1~	Mon Aug 31 18:04:47 1998
+++ linux/drivers/char/dn_keyb.c	Sun Dec  6 12:23:30 1998
@@ -55,7 +55,8 @@
 static u_char debug_buf1[4096],debug_buf2[4096],*debug_buf=&debug_buf1[0];
 static u_char *shadow_buf=&debug_buf2[0];
 static short debug_buf_count=0;
-static int debug_buf_overrun=0,debug_timer_running=0,debug_buffer_updated=0;
+static int debug_buf_overrun=0,debug_timer_running=0;
+static unsigned long debug_buffer_updated=0;
 static struct timer_list debug_keyb_timer = { NULL, NULL, 0, 0,
 											  debug_keyb_timer_handler };
 #endif
@@ -280,7 +281,7 @@
 	u_char *swap;
 	short length,i;
 
-	if((jiffies-debug_buffer_updated) > 100) {
+	if (time_after(jiffies, debug_buffer_updated + 100)) {
 		save_flags(flags);
 		cli();
 		length=debug_buf_count;		
@@ -422,7 +423,7 @@
    			!(prev_scancode==DNKEY_CTRL || prev_scancode==DNKEY_LSHIFT ||
        	   	prev_scancode==DNKEY_RSHIFT || prev_scancode==DNKEY_REPT ||
        	  	prev_scancode==DNKEY_LALT || prev_scancode==DNKEY_RALT)) {
-        		if(jiffies-lastkeypress > DNKEY_REPEAT_DELAY) {
+			if (time_after(jiffies, lastkeypress + DNKEY_REPEAT_DELAY)) {
 			/*    	printk("handle_scancode: %02x\n",prev_scancode); */
            			handle_scancode(prev_scancode);
 			  	}
@@ -491,8 +492,8 @@
 				debug_buf[debug_buf_count++]=data;
 				debug_buffer_updated=jiffies;	
 				if(!debug_timer_running) {
-					add_timer(&debug_keyb_timer);
 					debug_keyb_timer.expires=jiffies+10;
+					add_timer(&debug_keyb_timer);
 					debug_timer_running=1;
 				}
 			}
--- linux/drivers/char/lp_m68k.c.~1~	Mon Nov 30 18:24:42 1998
+++ linux/drivers/char/lp_m68k.c	Sun Dec  6 13:21:09 1998
@@ -41,8 +41,8 @@
 #include <linux/major.h>
 #include <linux/sched.h>
 #include <linux/string.h>
+#include <linux/timer.h>
 #include <linux/init.h>
-#include <asm/irq.h>
 #ifdef CONFIG_KMOD
 #include <linux/kmod.h>
 #endif
@@ -58,6 +58,7 @@
 #include <linux/malloc.h>
 #include <linux/interrupt.h>
 
+#include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
@@ -282,7 +283,7 @@
 	int dev = MINOR(inode->i_rdev);
 
 #ifdef LP_DEBUG
-	if (jiffies-lp_last_call > lp_table[dev]->time) {
+	if (time_after(jiffies, lp_last_call + lp_table[dev]->time)) {
 		lp_total_chars = 0;
 		lp_max_count = 1;
 	}
@@ -337,8 +338,7 @@
 			lp_total_chars = 0;
 #endif
 			current->state = TASK_INTERRUPTIBLE;
-			current->timeout = jiffies + timeout;
-			schedule();
+			schedule_timeout(timeout);
 		}
 	}
 	return temp - buf;
--- linux/drivers/char/m68kserial.c.~2~	Mon Nov  9 19:16:48 1998
+++ linux/drivers/char/m68kserial.c	Sun Dec  6 12:15:48 1998
@@ -985,7 +985,7 @@
 			schedule_timeout(info->timeout);
 			if (signal_pending(current))
 				break;
-			if (jiffies > timeout)
+			if (time_after(jiffies, timeout))
 				break;
 		}
 		current->state = TASK_RUNNING;

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

