Skip to content

Commit 5d14f32

Browse files
pmladekgregkh
authored andcommitted
usb: hub: keep hub->dev reference all the time when struct usb_hub lives
This is just a small optimization of the fix from the commit c605f3c ("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 <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Acked-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3512e7b commit 5d14f32

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/core/hub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,7 @@ static void hub_release(struct kref *kref)
16351635
{
16361636
struct usb_hub *hub = container_of(kref, struct usb_hub, kref);
16371637

1638+
usb_put_dev(hub->hdev);
16381639
usb_put_intf(to_usb_interface(hub->intfdev));
16391640
kfree(hub);
16401641
}
@@ -1800,6 +1801,7 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
18001801
INIT_DELAYED_WORK(&hub->leds, led_work);
18011802
INIT_DELAYED_WORK(&hub->init_work, NULL);
18021803
usb_get_intf(intf);
1804+
usb_get_dev(hdev);
18031805

18041806
usb_set_intfdata (intf, hub);
18051807
intf->needs_remote_wakeup = 1;
@@ -5026,10 +5028,9 @@ static void hub_events(void)
50265028

50275029
hub = list_entry(tmp, struct usb_hub, event_list);
50285030
kref_get(&hub->kref);
5029-
hdev = hub->hdev;
5030-
usb_get_dev(hdev);
50315031
spin_unlock_irq(&hub_event_lock);
50325032

5033+
hdev = hub->hdev;
50335034
hub_dev = hub->intfdev;
50345035
intf = to_usb_interface(hub_dev);
50355036
dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",
@@ -5142,7 +5143,6 @@ static void hub_events(void)
51425143
usb_autopm_put_interface(intf);
51435144
loop_disconnected:
51445145
usb_unlock_device(hdev);
5145-
usb_put_dev(hdev);
51465146
kref_put(&hub->kref, hub_release);
51475147

51485148
} /* end while (1) */

0 commit comments

Comments
 (0)