This patch is similar to the patch Randy sent out but has some more
verbose error messages as well as catches a couple of more areas where
it may fail silently.

One change of note is removing a magic number which was incorrect.
However, this would only cause problems with slightly out of spec hubs
AFICT. Perhaps this causes problems with the CTX monitors? It's a long
shot but worth a test I guess. 

The patch is against 2.4.0-test1

JE

--- linux-2.4.0-test1.orig/drivers/usb/hub.c    Sat May 20 11:23:54 2000
+++ linux-2.4.0-test1/drivers/usb/hub.c Wed May 31 14:42:23 2000
@@ -120,18 +120,25 @@
        struct usb_hub_descriptor *descriptor;
        struct usb_descriptor_header *header;
        struct usb_hub_status *hubsts;
-       int i;
+       int i, ret;
 
        /* Get the length first */
-       if (usb_get_hub_descriptor(dev, buffer, 4) < 0)
+       ret = usb_get_hub_descriptor(dev, buffer, sizeof(*header));
+       if (ret < 0) {
+               err("Unable to get partial hub descriptor (err = %d)", ret);
                return -1;
+       }
 
        header = (struct usb_descriptor_header *)buffer;
        bitmap = kmalloc(header->bLength, GFP_KERNEL);
-       if (!bitmap)
+       if (!bitmap) {
+               err("Unable to kmalloc %d bytes for bitmap", header->bLength);
                return -1;
+       }
 
-       if (usb_get_hub_descriptor(dev, bitmap, header->bLength) < 0) {
+       ret = usb_get_hub_descriptor(dev, bitmap, header->bLength);
+       if (ret < 0) {
+               err("Unable to get hub descriptor (err = %d)", ret);
                kfree(bitmap);
                return -1;
        }
@@ -182,8 +189,11 @@
 
        kfree(bitmap);
 
-       if (usb_get_hub_status(dev, buffer) < 0)
+       ret = usb_get_hub_status(dev, buffer);
+       if (ret < 0) {
+               err("Unable to get hub status (err = %d)", ret);
                return -1;
+       }
 
        hubsts = (struct usb_hub_status *)buffer;
        dbg("local power source is %s",
@@ -225,12 +235,16 @@
        endpoint = &interface->endpoint[0];
 
        /* Output endpoint? Curiousier and curiousier.. */
-       if (!(endpoint->bEndpointAddress & USB_DIR_IN))
+       if (!(endpoint->bEndpointAddress & USB_DIR_IN)) {
+               err("Device is hub class, but has output endpoint?");
                return NULL;
+       }
 
        /* If it's not an interrupt endpoint, we'd better punt! */
-       if ((endpoint->bmAttributes & 3) != 3)
+       if ((endpoint->bmAttributes & 3) != 3) {
+               err("Device is hub class, but has endpoint other than interrupt?");
                return NULL;
+       }
 
        /* We found a hub */
        info("USB hub found");
@@ -326,12 +340,13 @@
        struct usb_device *usb;
        struct usb_port_status portsts;
        unsigned short portstatus, portchange;
-       int tries;
+       int ret, tries;
 
        wait_ms(100);
-       /* Check status */
-       if (usb_get_port_status(hub, port + 1, &portsts)<0) {
-               err("get_port_status failed");
+
+       ret = usb_get_port_status(hub, port + 1, &portsts);
+       if (ret < 0) {
+               err("get_port_status(%d) failed (err = %d)", port + 1, ret);
                return;
        }
 
@@ -353,19 +368,19 @@
        }
        wait_ms(400);   
 
-       /* Reset the port */
-
 #define MAX_TRIES 5
-       
-       for(tries=0;tries<MAX_TRIES;tries++) {
-               
+
+       /* Reset the port */
+       for (tries = 0; tries < MAX_TRIES ; tries++) {
                usb_set_port_feature(hub, port + 1, USB_PORT_FEAT_RESET);
                wait_ms(200);   
-               
-               if (usb_get_port_status(hub, port + 1, &portsts)<0) {
-                       err("get_port_status failed");
+
+               ret = usb_get_port_status(hub, port + 1, &portsts);
+               if (ret < 0) {
+                       err("get_port_status(%d) failed (err = %d)", port + 1, ret);
                        return;
                }
+
                portstatus = le16_to_cpu(portsts.wPortStatus);
                portchange = le16_to_cpu(portsts.wPortChange);
                dbg("portstatus %x, change %x, %s", portstatus ,portchange,
@@ -381,7 +396,7 @@
                wait_ms(200);
        }
 
-       if (tries==MAX_TRIES) {
+       if (tries >= MAX_TRIES) {
                err("Cannot enable port %i after %i retries, disabling port.", port+1, 
MAX_TRIES);
                err("Maybe the USB cable is bad?");
                return;
@@ -390,7 +405,6 @@
        usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_RESET);
 
        /* Allocate a new device struct for it */
-
        usb = usb_alloc_dev(hub, hub->bus);
        if (!usb) {
                err("couldn't allocate usb_device");
@@ -556,10 +570,9 @@
 }
 
 static struct usb_driver hub_driver = {
-       "hub",
-       hub_probe,
-       hub_disconnect,
-       { NULL, NULL }
+       name:           "hub",
+       probe:          hub_probe,
+       disconnect:     hub_disconnect
 };
 
 /*
@@ -569,8 +582,10 @@
 {
        int pid;
 
-       if (usb_register(&hub_driver) < 0)
+       if (usb_register(&hub_driver) < 0) {
+               err("Unable to register USB hub driver");
                return -1;
+       }
 
        pid = kernel_thread(usb_hub_thread, NULL,
                CLONE_FS | CLONE_FILES | CLONE_SIGHAND);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to