From akpm@osdl.org Wed Jul 27 01:14:12 2005
Message-Id: <200507270809.j6R89UuV009567@shell0.pdx.osdl.net>
Subject: USB Storage: fix something
From: Alan Stern <stern@rowland.harvard.edu>
To: greg@kroah.com
Date: Wed, 27 Jul 2005 01:08:33 -0700


This is the second of two patches for usb-storage.  I don't think it really
addresses the problem raised by this bug report, but I could be wrong. 
It's closely related, at any rate, and it does fix a real loophole.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


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

--- gregkh-2.6.orig/drivers/usb/storage/usb.c	2005-07-27 22:34:18.000000000 -0700
+++ gregkh-2.6/drivers/usb/storage/usb.c	2005-07-27 22:34:51.000000000 -0700
@@ -833,6 +833,19 @@
 	/* Wait for the current command to finish, then remove the host */
 	down(&us->dev_semaphore);
 	up(&us->dev_semaphore);
+
+	/* 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 */
 	scsi_remove_host(us_to_host(us));
 }