Skip to contentSkip to conversation

use mod_timer in scsi_add_timer

PATCH In review Christoph Hellwig 2 participants 4 messages Aug 31, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use mod_timer in scsi_add_timer

del_timer / modify / add_timer is racy. mod_timer on not active timer is fine, though.

Note that eh_timeout handling looks fishy in more places, I'll audit it.

drivers/scsi/scsi_error.c +1 -12
@@ -105,24 +105,13 @@
 void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
 		    void (*complete)(struct scsi_cmnd *))
 {
-
-	/*
-	 * If the clock was already running for this command, then
-	 * first delete the timer.  The timer handling code gets rather
-	 * confused if we don't do this.
-	 */
-	if (scmd->eh_timeout.function)
-		del_timer(&scmd->eh_timeout);
-
 	scmd->eh_timeout.data = (unsigned long)scmd;
-	scmd->eh_timeout.expires = jiffies + timeout;
 	scmd->eh_timeout.function = (void (*)(unsigned long)) complete;
+	mod_timer(&scmd->eh_timeout, jiffies + timeout);
 
 	SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p, time:"
 					  " %d, (%p)\n", __FUNCTION__,
 					  scmd, timeout, complete));
-
-	add_timer(&scmd->eh_timeout);
 }
 
 /**
#1 lore raw

drivers/scsi/scsi_error.c line 109

Quoted 4 lines · Christoph Hellwig
drivers/scsi/scsi_error.c +0 -2
-
 	scmd->eh_timeout.data = (unsigned long)scmd;
-	scmd->eh_timeout.expires = jiffies + timeout;
 	scmd->eh_timeout.function = (void (*)(unsigned long)) complete;

And your change is racy too. You might now call the timer function with the data from the old timeout and the function of the new...

You just need the del_timer to be unconditional, the other change isn't safe.

#2 lore raw
Quoted 8 lines · Alan Cox

drivers/scsi/scsi_error.c line 109

Quoted 4 lines · Christoph Hellwig
drivers/scsi/scsi_error.c +0 -2
-
 	scmd->eh_timeout.data = (unsigned long)scmd;
-	scmd->eh_timeout.expires = jiffies + timeout;
 	scmd->eh_timeout.function = (void (*)(unsigned long)) complete;

And your change is racy too. You might now call the timer function with the data from the old timeout and the function of the new...

The data always is scmd.

#3 lore raw
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines

And your change is racy too. You might now call the timer function with the data from the old timeout and the function of the new...

The data always is scmd.

So why are you setting that field ?

Even if it is true now its an invitation to a very hard to track down and horrible bug.