From c4db8aba7bb80c8a287acfe6007fe0037cfade64 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 22 Feb 2019 17:09:09 -0500 Subject: [PATCH] XHCI: Delete the device in FreeDevice() before tearing down internal state. We don't properly tear down endpoints, etc. yet, but when we do, this will be important as the device destructors are what tells us to do that. --- src/add-ons/kernel/busses/usb/xhci.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp b/src/add-ons/kernel/busses/usb/xhci.cpp index 033fd68234..a76e7e2301 100644 --- a/src/add-ons/kernel/busses/usb/xhci.cpp +++ b/src/add-ons/kernel/busses/usb/xhci.cpp @@ -1425,6 +1425,11 @@ XHCI::FreeDevice(Device *device) { uint8 slot = fPortSlots[device->HubPort()]; TRACE("FreeDevice() port %d slot %d\n", device->HubPort(), slot); + + // Delete the device first, so it cleans up its pipes and tells us + // what we need to destroy before we tear down our internal state. + delete device; + DisableSlot(slot); fDcba->baseAddress[slot] = 0; fPortSlots[device->HubPort()] = 0; @@ -1432,7 +1437,6 @@ XHCI::FreeDevice(Device *device) delete_area(fDevices[slot].input_ctx_area); delete_area(fDevices[slot].device_ctx_area); fDevices[slot].state = XHCI_STATE_DISABLED; - delete device; }