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.

Greg, please apply.

Signed-off-by: Matthew Dharm <[EMAIL PROTECTED]>

Matt


# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/05/31 19:46:27-07:00 [EMAIL PROTECTED] 
#   as274 + significant enhancements
# 
# drivers/usb/storage/usb.c
#   2004/05/31 19:46:03-07:00 [EMAIL PROTECTED] +8 -2
#   as274 + significant enhancements
# 
# drivers/usb/storage/transport.c
#   2004/05/31 19:46:03-07:00 [EMAIL PROTECTED] +13 -10
#   as274 + significant enhancements
# 
diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c   Sun Jun  6 22:22:29 2004
+++ b/drivers/usb/storage/transport.c   Sun Jun  6 22:22:29 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 Sun Jun  6 22:22:29 2004
+++ b/drivers/usb/storage/usb.c Sun Jun  6 22:22:29 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 */
-- 
Matthew Dharm                              Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

I think the problem is there's a nut loose on your keyboard.
                                        -- Greg to Customer
User Friendly, 1/5/1999 

Attachment: pgpHMRwtCWxVe.pgp
Description: PGP signature

Reply via email to