]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
usb: hub: keep hub->dev reference all the time when struct usb_hub lives
authorPetr Mladek <pmladek@suse.cz>
Fri, 19 Sep 2014 15:32:19 +0000 (17:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Sep 2014 05:31:11 +0000 (22:31 -0700)
This is just a small optimization of the fix from the commit c605f3cdff53a743f6
("usb: hub: take hub->hdev reference when processing from eventlist).

We do not need to take the reference for each event. Instead we could get it
when struct usb_hub is allocated and put it when it is released. By other words,
we could handle it the same way as the reference for hub->intfdev.

The motivation is that it will make the life easier when switching from khubd
kthread to a workqueue.

Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Petr Mladek <pmladek@suse.cz>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hub.c

index d5419292f89f9484a437b03b7cdc6555954173cd..6a9f11fbc2eb1f4e8417b135c1464460aa8addb0 100644 (file)
@@ -1635,6 +1635,7 @@ static void hub_release(struct kref *kref)
 {
        struct usb_hub *hub = container_of(kref, struct usb_hub, kref);
 
+       usb_put_dev(hub->hdev);
        usb_put_intf(to_usb_interface(hub->intfdev));
        kfree(hub);
 }
@@ -1800,6 +1801,7 @@ descriptor_error:
        INIT_DELAYED_WORK(&hub->leds, led_work);
        INIT_DELAYED_WORK(&hub->init_work, NULL);
        usb_get_intf(intf);
+       usb_get_dev(hdev);
 
        usb_set_intfdata (intf, hub);
        intf->needs_remote_wakeup = 1;
@@ -5026,10 +5028,9 @@ static void hub_events(void)
 
                hub = list_entry(tmp, struct usb_hub, event_list);
                kref_get(&hub->kref);
-               hdev = hub->hdev;
-               usb_get_dev(hdev);
                spin_unlock_irq(&hub_event_lock);
 
+               hdev = hub->hdev;
                hub_dev = hub->intfdev;
                intf = to_usb_interface(hub_dev);
                dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",
@@ -5142,7 +5143,6 @@ static void hub_events(void)
                usb_autopm_put_interface(intf);
  loop_disconnected:
                usb_unlock_device(hdev);
-               usb_put_dev(hdev);
                kref_put(&hub->kref, hub_release);
 
        } /* end while (1) */