Greg:

This patch adds a pointer to the hub's usb_device into the usb_hub private 
structure.  It's a small change, and permits a small amount of 
simplification in a few spots, i.e., avoid calling interface_to_usbdev().  
This doesn't really do much in itself, but it's a prerequisite for the 
next patch.  (A situation arises where we can't use the interface pointer 
to find the usb_device because the interface might not exist.)

Please apply.

Alan Stern



Signed-off-by: Alan Stern <[EMAIL PROTECTED]>

===== drivers/usb/core/hub.c 1.178 vs edited =====
--- 1.178/drivers/usb/core/hub.c        Thu Jun 24 16:43:27 2004
+++ edited/drivers/usb/core/hub.c       Thu Jul  1 14:26:05 2004
@@ -138,7 +138,7 @@
 static void led_work (void *__hub)
 {
        struct usb_hub          *hub = __hub;
-       struct usb_device       *hdev = interface_to_usbdev (hub->intf);
+       struct usb_device       *hdev = hub->hdev;
        unsigned                i;
        unsigned                changed = 0;
        int                     cursor = -1;
@@ -298,7 +298,7 @@
        while (!list_empty (&hub->tt.clear_list)) {
                struct list_head        *temp;
                struct usb_tt_clear     *clear;
-               struct usb_device       *hdev;
+               struct usb_device       *hdev = hub->hdev;
                int                     status;
 
                temp = hub->tt.clear_list.next;
@@ -307,7 +307,6 @@
 
                /* drop lock so HCD can concurrently report other TT errors */
                spin_unlock_irqrestore (&hub->tt.lock, flags);
-               hdev = interface_to_usbdev (hub->intf);
                status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt);
                spin_lock_irqsave (&hub->tt.lock, flags);
 
@@ -368,15 +367,14 @@
 
 static void hub_power_on(struct usb_hub *hub)
 {
-       struct usb_device *hdev;
        int i;
 
        /* if hub supports power switching, enable power on each port */
        if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_LPSM) < 2) {
                dev_dbg(&hub->intf->dev, "enabling power on all ports\n");
-               hdev = interface_to_usbdev(hub->intf);
                for (i = 0; i < hub->descriptor->bNbrPorts; i++)
-                       set_port_feature(hdev, i + 1, USB_PORT_FEAT_POWER);
+                       set_port_feature(hub->hdev, i + 1,
+                                       USB_PORT_FEAT_POWER);
        }
 
        /* Wait for power to be enabled */
@@ -386,10 +384,9 @@
 static int hub_hub_status(struct usb_hub *hub,
                u16 *status, u16 *change)
 {
-       struct usb_device *hdev = interface_to_usbdev (hub->intf);
        int ret;
 
-       ret = get_hub_status(hdev, &hub->status->hub);
+       ret = get_hub_status(hub->hdev, &hub->status->hub);
        if (ret < 0)
                dev_err (&hub->intf->dev,
                        "%s failed (err = %d)\n", __FUNCTION__, ret);
@@ -404,7 +401,7 @@
 static int hub_configure(struct usb_hub *hub,
        struct usb_endpoint_descriptor *endpoint)
 {
-       struct usb_device *hdev = interface_to_usbdev (hub->intf);
+       struct usb_device *hdev = hub->hdev;
        struct device *hub_dev = &hub->intf->dev;
        u16 hubstatus, hubchange;
        unsigned int pipe;
@@ -629,11 +626,13 @@
 static void hub_disconnect(struct usb_interface *intf)
 {
        struct usb_hub *hub = usb_get_intfdata (intf);
+       struct usb_device *hdev;
 
        if (!hub)
                return;
+       hdev = hub->hdev;
 
-       if (interface_to_usbdev(intf)->speed == USB_SPEED_HIGH)
+       if (hdev->speed == USB_SPEED_HIGH)
                highspeed_hubs--;
 
        usb_set_intfdata (intf, NULL);
@@ -644,7 +643,6 @@
                hub->urb = NULL;
        }
 
-       /* Delete it and then reset it */
        spin_lock_irq(&hub_event_lock);
        list_del_init(&hub->event_list);
        spin_unlock_irq(&hub_event_lock);
@@ -666,8 +664,7 @@
        }
 
        if (hub->buffer) {
-               usb_buffer_free(interface_to_usbdev(intf),
-                               sizeof(*hub->buffer), hub->buffer,
+               usb_buffer_free(hdev, sizeof(*hub->buffer), hub->buffer,
                                hub->buffer_dma);
                hub->buffer = NULL;
        }
@@ -725,6 +722,7 @@
 
        INIT_LIST_HEAD(&hub->event_list);
        hub->intf = intf;
+       hub->hdev = hdev;
        INIT_WORK(&hub->leds, led_work, hub);
 
        usb_set_intfdata (intf, hub);
@@ -776,7 +774,7 @@
 
 static int hub_reset(struct usb_hub *hub)
 {
-       struct usb_device *hdev = interface_to_usbdev(hub->intf);
+       struct usb_device *hdev = hub->hdev;
        int i;
 
        /* Disconnect any attached devices */
@@ -1496,8 +1494,9 @@
 }
 
 static unsigned
-hub_power_remaining (struct usb_hub *hub, struct usb_device *hdev)
+hub_power_remaining (struct usb_hub *hub)
 {
+       struct usb_device *hdev = hub->hdev;
        int remaining;
        unsigned i;
 
@@ -1538,7 +1537,7 @@
 static void hub_port_connect_change(struct usb_hub *hub, int port,
                                        u16 portstatus, u16 portchange)
 {
-       struct usb_device *hdev = interface_to_usbdev(hub->intf);
+       struct usb_device *hdev = hub->hdev;
        struct device *hub_dev = &hub->intf->dev;
        int status, i;
  
@@ -1683,7 +1682,7 @@
                if (status)
                        goto loop;
 
-               status = hub_power_remaining(hub, hdev);
+               status = hub_power_remaining(hub);
                if (status)
                        dev_dbg(hub_dev,
                                "%dmA power budget left\n",
@@ -1737,7 +1736,7 @@
                list_del_init(tmp);
 
                hub = list_entry(tmp, struct usb_hub, event_list);
-               hdev = interface_to_usbdev(hub->intf);
+               hdev = hub->hdev;
                hub_dev = &hub->intf->dev;
 
                usb_get_dev(hdev);
===== drivers/usb/core/hub.h 1.33 vs edited =====
--- 1.33/drivers/usb/core/hub.h Wed Jun 23 15:04:52 2004
+++ edited/drivers/usb/core/hub.h       Thu Jul  1 11:48:09 2004
@@ -187,6 +187,7 @@
 
 struct usb_hub {
        struct usb_interface    *intf;          /* the "real" device */
+       struct usb_device       *hdev;
        struct urb              *urb;           /* for interrupt polling pipe */
 
        /* buffer for urb ... 1 bit each for hub and children, rounded up */



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to