tree 6fc0d50a4d286df33b18f21e0994b09637d0c6c8
parent 77f46328fb83b64befd889ebce6d7fb959932509
author Matthew Dharm <[EMAIL PROTECTED]> Fri, 29 Jul 2005 04:45:50 -0700
committer Greg Kroah-Hartman <[EMAIL PROTECTED]> Fri, 09 Sep 2005 06:22:55 -0700

[PATCH] USB Storage: close a race condition in disconnect near queuecommand

This patch started life as as534, and has been re-diffed against the latest

usb-storage has a small loophole, a window between the time queuecommand
accepts a new command and the time the control thread starts to execute
it.  If disconnect is called during that window, the driver won't cancel
the pending command -- we've been relying on the SCSI core to cancel it
for us during host removal.  But it's better for usb-storage to cancel
it;  this avoids races and reduces reliance on the SCSI core.
Fortunately cancelling these commands is easy to do; the key is to do it
_before_ calling scsi_remove_host.

Signed-off-by: Alan Stern <[EMAIL PROTECTED]>
Signed-off-by: Matthew Dharm <[EMAIL PROTECTED]>
Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>

 drivers/usb/storage/usb.c |   13 +++++++++++++
 1 files changed, 13 insertions(+)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -833,6 +833,19 @@ static void quiesce_and_remove_host(stru
        /* Wait for the current command to finish, then remove the host */
+       /* queuecommand won't accept any new commands and the control
+        * thread won't execute a previously-queued command.  If there
+        * is such a command pending, complete it with an error. */
+       if (us->srb) {
+               us->srb->result = DID_NO_CONNECT << 16;
+               scsi_lock(us_to_host(us));
+               us->srb->scsi_done(us->srb);
+               us->srb = NULL;
+               scsi_unlock(us_to_host(us));
+       }
+       /* Now we own no commands so it's safe to remove the SCSI host */
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to