From d2627ecfccd87cfe9caf4dd8cbb866d15be96ec8 Mon Sep 17 00:00:00 2001 From: Xiaoguang Wu Date: Fri, 14 Dec 2018 19:15:56 +0800 Subject: [PATCH] DM USB: xHCI: fix an issues for failing to enumerate device This is an obvious bug, which releases memory but still access the data on the released memory. It is risky operation, and may result failing to do normal enumlation process. This patch is used to fix it. Tracked-On: #1893 Signed-off-by: Xiaoguang Wu Reviewed-by: Liang Yang Acked-by: Yu Wang --- devicemodel/hw/pci/xhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index 23a99dea5..79e5d0f12 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -1802,8 +1802,6 @@ pci_xhci_cmd_disable_slot(struct pci_xhci_vdev *xdev, uint32_t slot) goto done; } - pci_xhci_dev_destroy(dev); - for (j = 0; j < XHCI_MAX_VIRT_PORTS; ++j) { path = &xdev->vbdp_devs[j].path; @@ -1818,6 +1816,9 @@ pci_xhci_cmd_disable_slot(struct pci_xhci_vdev *xdev, uint32_t slot) } UPRINTF(LINF, "disable slot %d for native device %d-%s\r\n", slot, di->path.bus, usb_dev_path(&di->path)); + + /* release all the resource allocated for virtual device */ + pci_xhci_dev_destroy(dev); } else UPRINTF(LWRN, "invalid slot %d\r\n", slot);