All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use mod_timer in scsi_add_timer
@ 2003-08-31 11:28 Christoph Hellwig
  2003-08-31 12:51 ` Alan Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2003-08-31 11:28 UTC (permalink / raw)
  To: James Bottomley; +Cc: linux-scsi

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.


--- 1.62/drivers/scsi/scsi_error.c	Mon Aug 25 15:37:40 2003
+++ edited/drivers/scsi/scsi_error.c	Thu Aug 28 23:04:57 2003
@@ -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);
 }
 
 /**

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mod_timer in scsi_add_timer
  2003-08-31 11:28 [PATCH] use mod_timer in scsi_add_timer Christoph Hellwig
@ 2003-08-31 12:51 ` Alan Cox
  2003-08-31 12:53   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Cox @ 2003-08-31 12:51 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: James Bottomley, linux-scsi

On Sul, 2003-08-31 at 12:28, Christoph Hellwig wrote:
> -
>  	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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mod_timer in scsi_add_timer
  2003-08-31 12:51 ` Alan Cox
@ 2003-08-31 12:53   ` Christoph Hellwig
  2003-08-31 13:24     ` Alan Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2003-08-31 12:53 UTC (permalink / raw)
  To: Alan Cox; +Cc: James Bottomley, linux-scsi

On Sun, Aug 31, 2003 at 01:51:58PM +0100, Alan Cox wrote:
> On Sul, 2003-08-31 at 12:28, Christoph Hellwig wrote:
> > -
> >  	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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mod_timer in scsi_add_timer
  2003-08-31 12:53   ` Christoph Hellwig
@ 2003-08-31 13:24     ` Alan Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Cox @ 2003-08-31 13:24 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: James Bottomley, linux-scsi

On Sul, 2003-08-31 at 13:53, Christoph Hellwig wrote:
> > 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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-08-31 13:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-31 11:28 [PATCH] use mod_timer in scsi_add_timer Christoph Hellwig
2003-08-31 12:51 ` Alan Cox
2003-08-31 12:53   ` Christoph Hellwig
2003-08-31 13:24     ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.