aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorMathias Nyman <mathias.nyman@linux.intel.com>2017-01-03 11:28:43 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-03 11:37:32 -0500
commitee8665e28e8d90ce69d4abe5a469c14a8707ae0e (patch)
treebfbcdd5a93b2a1d1f2d3425535fe74aa448ea30d /drivers/usb
parent8d6bbff67796262b5296b745989e4c9d9f2b4894 (diff)
xhci: free xhci virtual devices with leaf nodes first
the tt_info provided by a HS hub might be in use to by a child device Make sure we free the devices in the correct order. This is needed in special cases such as when xhci controller is reset when resuming from hibernate, and all virt_devices are freed. Also free the virt_devices starting from max slot_id as children more commonly have higher slot_id than parent. CC: <stable@vger.kernel.org> Reported-by: Guenter Roeck <groeck@chromium.org> Tested-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/host/xhci-mem.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 321de2e0161b..1dfd1c223cf2 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -979,6 +979,40 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
979 xhci->devs[slot_id] = NULL; 979 xhci->devs[slot_id] = NULL;
980} 980}
981 981
982/*
983 * Free a virt_device structure.
984 * If the virt_device added a tt_info (a hub) and has children pointing to
985 * that tt_info, then free the child first. Recursive.
986 * We can't rely on udev at this point to find child-parent relationships.
987 */
988void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
989{
990 struct xhci_virt_device *vdev;
991 struct list_head *tt_list_head;
992 struct xhci_tt_bw_info *tt_info, *next;
993 int i;
994
995 vdev = xhci->devs[slot_id];
996 if (!vdev)
997 return;
998
999 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
1000 list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
1001 /* is this a hub device that added a tt_info to the tts list */
1002 if (tt_info->slot_id == slot_id) {
1003 /* are any devices using this tt_info? */
1004 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
1005 vdev = xhci->devs[i];
1006 if (vdev && (vdev->tt_info == tt_info))
1007 xhci_free_virt_devices_depth_first(
1008 xhci, i);
1009 }
1010 }
1011 }
1012 /* we are now at a leaf device */
1013 xhci_free_virt_device(xhci, slot_id);
1014}
1015
982int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, 1016int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
983 struct usb_device *udev, gfp_t flags) 1017 struct usb_device *udev, gfp_t flags)
984{ 1018{
@@ -1828,8 +1862,8 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1828 } 1862 }
1829 } 1863 }
1830 1864
1831 for (i = 1; i < MAX_HC_SLOTS; ++i) 1865 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--)
1832 xhci_free_virt_device(xhci, i); 1866 xhci_free_virt_devices_depth_first(xhci, i);
1833 1867
1834 dma_pool_destroy(xhci->segment_pool); 1868 dma_pool_destroy(xhci->segment_pool);
1835 xhci->segment_pool = NULL; 1869 xhci->segment_pool = NULL;