]> git.hungrycats.org Git - linux/commitdiff
[PATCH] USB: Store pointer to usb_device in private hub structure
authorAlan Stern <stern@rowland.harvard.edu>
Wed, 14 Jul 2004 07:41:28 +0000 (00:41 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 14 Jul 2004 07:41:28 +0000 (00:41 -0700)
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.)

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/usb/core/hub.c
drivers/usb/core/hub.h

index 2331688719ce3162e6e735d5ba333e8f47d14379..ead5b3cfef452abaf3c2fc49b660f96d4b45bdba 100644 (file)
@@ -138,7 +138,7 @@ static void set_port_led(
 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 @@ static void hub_tt_kevent (void *arg)
        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 @@ static void hub_tt_kevent (void *arg)
 
                /* 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 @@ void usb_hub_tt_clear_buffer (struct usb_device *udev, int pipe)
 
 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 void hub_power_on(struct usb_hub *hub)
 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_hub_status(struct usb_hub *hub,
 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 unsigned highspeed_hubs;
 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 @@ static void hub_disconnect(struct usb_interface *intf)
                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 @@ static void hub_disconnect(struct usb_interface *intf)
        }
 
        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 @@ descriptor_error:
 
        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 @@ hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data)
 
 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 */
@@ -1498,8 +1496,9 @@ check_highspeed (struct usb_hub *hub, struct usb_device *udev, int port)
 }
 
 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;
 
@@ -1540,7 +1539,7 @@ hub_power_remaining (struct usb_hub *hub, struct usb_device *hdev)
 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;
  
@@ -1685,7 +1684,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port,
                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",
@@ -1739,7 +1738,7 @@ static void hub_events(void)
                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);
index 10fd2f35954b2cadbc278c60ac6e1f94605e34da..9e81738fd2fc0fc708b6e10c171fde5bdf6d69f2 100644 (file)
@@ -187,6 +187,7 @@ extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
 
 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 */