Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 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>

authored by

Petr Mladek and committed by
Greg Kroah-Hartman
5d14f323 3512e7bf

+3 -3
+3 -3
drivers/usb/core/hub.c
··· 1635 1635 { 1636 1636 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); 1637 1637 1638 + usb_put_dev(hub->hdev); 1638 1639 usb_put_intf(to_usb_interface(hub->intfdev)); 1639 1640 kfree(hub); 1640 1641 } ··· 1801 1800 INIT_DELAYED_WORK(&hub->leds, led_work); 1802 1801 INIT_DELAYED_WORK(&hub->init_work, NULL); 1803 1802 usb_get_intf(intf); 1803 + usb_get_dev(hdev); 1804 1804 1805 1805 usb_set_intfdata (intf, hub); 1806 1806 intf->needs_remote_wakeup = 1; ··· 5028 5026 5029 5027 hub = list_entry(tmp, struct usb_hub, event_list); 5030 5028 kref_get(&hub->kref); 5031 - hdev = hub->hdev; 5032 - usb_get_dev(hdev); 5033 5029 spin_unlock_irq(&hub_event_lock); 5034 5030 5031 + hdev = hub->hdev; 5035 5032 hub_dev = hub->intfdev; 5036 5033 intf = to_usb_interface(hub_dev); 5037 5034 dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n", ··· 5143 5142 usb_autopm_put_interface(intf); 5144 5143 loop_disconnected: 5145 5144 usb_unlock_device(hdev); 5146 - usb_put_dev(hdev); 5147 5145 kref_put(&hub->kref, hub_release); 5148 5146 5149 5147 } /* end while (1) */