ChangeSet 1.1722.97.41, 2004/06/07 12:59:12-07:00, mdharm-usb@one-eyed-alien.net

[PATCH] USB Storage: GetMaxLUN tightening

This patch started life from Alan Stern as as274, and has been heavily
modified.  It narrows the case where a clear_halt() is issued after a
failed GetMaxLUN command to only a STALL case.

Since the only legimate responses to a GetMaxLUN are STALL or data,
anything else is now considered a fatal error and we give up on the device.


Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 drivers/usb/storage/transport.c |   23 +++++++++++++----------
 drivers/usb/storage/usb.c       |   10 ++++++++--
 2 files changed, 21 insertions(+), 12 deletions(-)


diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c	Fri Jun 18 11:01:45 2004
+++ b/drivers/usb/storage/transport.c	Fri Jun 18 11:01:45 2004
@@ -908,26 +908,29 @@
 				 USB_RECIP_INTERFACE,
 				 0, us->ifnum, us->iobuf, 1, HZ);
 
+	US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", 
+		  result, us->iobuf[0]);
+
+	/* if we have a successful request, return the result */
+	if (result == 1)
+		return us->iobuf[0];
+
 	/* 
 	 * Some devices (i.e. Iomega Zip100) need this -- apparently
 	 * the bulk pipes get STALLed when the GetMaxLUN request is
 	 * processed.   This is, in theory, harmless to all other devices
 	 * (regardless of if they stall or not).
 	 */
-	if (result < 0) {
+	if (result == -EPIPE) {
 		usb_stor_clear_halt(us, us->recv_bulk_pipe);
 		usb_stor_clear_halt(us, us->send_bulk_pipe);
+		/* return the default -- no LUNs */
+		return 0;
 	}
 
-	US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", 
-		  result, us->iobuf[0]);
-
-	/* if we have a successful request, return the result */
-	if (result == 1)
-		return us->iobuf[0];
-
-	/* return the default -- no LUNs */
-	return 0;
+	/* An answer or a STALL are the only valid responses.  If we get
+	 * something else, return an indication of error */
+	return -1;
 }
 
 int usb_stor_Bulk_transport(Scsi_Cmnd *srb, struct us_data *us)
diff -Nru a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
--- a/drivers/usb/storage/usb.c	Fri Jun 18 11:01:45 2004
+++ b/drivers/usb/storage/usb.c	Fri Jun 18 11:01:45 2004
@@ -754,8 +754,14 @@
 	down(&us->dev_semaphore);
 
 	/* For bulk-only devices, determine the max LUN value */
-	if (us->protocol == US_PR_BULK)
-		us->max_lun = usb_stor_Bulk_max_lun(us);
+	if (us->protocol == US_PR_BULK) {
+		p = usb_stor_Bulk_max_lun(us);
+		if (p < 0) {
+			up(&us->dev_semaphore);
+			return p;
+		}
+		us->max_lun = p;
+	}
 
 	/* Just before we start our control thread, initialize
 	 * the device if it needs initialization */
