On Fri, 7 Jan 2005, David Brownell wrote:

> That patch looked OK, but I might prefer one that also validated
> the ep0 maxpacket size too.  (The patch I sent _only_ validated
> that field.)  How about something more like
> 
>    if (r < 8 || buf->bDescriptorType != USB_DT_DEVICE) {
>       r = -EPROTO;
>       continue;
>    }
>    switch (buf->bMaxPacketSize0) {
>    case 8: case 16: case 32: case 64:  break;
>    default:
>       r = -EPROTO;
>       continue;
>    }
> 
> No real point in accepting a read of 3 bytes and then relying
> on the non-existent 8th byte ... or relying on obviously borked
> data in that byte!

Okay, here's a patch that looks pretty good to me.  The only thing I'm not 
sure about is that it may retry _too_ aggressively.  If you like it I'll 
submit it to Greg.

Alan Stern


===== drivers/usb/core/hub.c 1.223 vs edited =====
--- 1.223/drivers/usb/core/hub.c        2005-01-11 12:14:56 -05:00
+++ edited/drivers/usb/core/hub.c       2005-01-13 11:51:32 -05:00
@@ -75,7 +75,7 @@
 MODULE_PARM_DESC(old_scheme_first,
                 "start with the old device initialization scheme");
 
-static int use_both_schemes = 0;
+static int use_both_schemes = 1;
 module_param(use_both_schemes, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(use_both_schemes,
                "try the other device initialization scheme if the "
@@ -2180,24 +2180,35 @@
                                retval = -ENOMEM;
                                continue;
                        }
-                       buf->bMaxPacketSize0 = 0;
 
                        /* Use a short timeout the first time through,
                         * so that recalcitrant full-speed devices with
                         * 8- or 16-byte ep0-maxpackets won't slow things
                         * down tremendously by NAKing the unexpectedly
-                        * early status stage.  Also, retry on length 0
-                        * or stall; some devices are flakey.
+                        * early status stage.  Also, retry on all errors;
+                        * some devices are flakey.
                         */
                        for (j = 0; j < 3; ++j) {
+                               buf->bMaxPacketSize0 = 0;
                                r = usb_control_msg(udev, usb_rcvaddr0pipe(),
                                        USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
                                        USB_DT_DEVICE << 8, 0,
                                        buf, GET_DESCRIPTOR_BUFSIZE,
                                        (i ? HZ * USB_CTRL_GET_TIMEOUT : HZ));
-                               if (r == 0 || r == -EPIPE)
-                                       continue;
-                               if (r < 0)
+                               switch (buf->bMaxPacketSize0) {
+                               case 8: case 16: case 32: case 64:
+                                       if (buf->bDescriptorType ==
+                                                       USB_DT_DEVICE) {
+                                               r = 0;
+                                               break;
+                                       }
+                                       /* FALL THROUGH */
+                               default:
+                                       if (r == 0)
+                                               r = -EPROTO;
+                                       break;
+                               }
+                               if (r == 0)
                                        break;
                        }
                        udev->descriptor.bMaxPacketSize0 =
@@ -2213,10 +2224,7 @@
                                retval = -ENODEV;
                                goto fail;
                        }
-                       switch (udev->descriptor.bMaxPacketSize0) {
-                       case 64: case 32: case 16: case 8:
-                               break;
-                       default:
+                       if (r) {
                                dev_err(&udev->dev, "device descriptor "
                                                "read/%s, error %d\n",
                                                "64", r);



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to