From a54fc27a11ff857643d4b0dacaf641cc9ceb9ef3 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 22 Feb 2019 01:23:08 -0500 Subject: [PATCH] XHCI: Check the device object initialized successfully before adding it. Fixes various NULL dereferences in other parts of the USB stack when the XHCI controller is not behaving quite as expected. Possibly related to #13403. --- src/add-ons/kernel/busses/usb/xhci.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp b/src/add-ons/kernel/busses/usb/xhci.cpp index e80407022d..3831098c57 100644 --- a/src/add-ons/kernel/busses/usb/xhci.cpp +++ b/src/add-ons/kernel/busses/usb/xhci.cpp @@ -1395,8 +1395,12 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort, deviceObject = new(std::nothrow) Device(parent, hubAddress, hubPort, deviceDescriptor, device->address + 1, speed, false, device); } - if (deviceObject == NULL) { - TRACE_ERROR("no memory to allocate device\n"); + if (deviceObject == NULL || deviceObject->InitCheck() != B_OK) { + if (deviceObject == NULL) { + TRACE_ERROR("no memory to allocate device\n"); + } else { + TRACE_ERROR("device object failed to initialize\n"); + } device->state = XHCI_STATE_DISABLED; delete_area(device->input_ctx_area); delete_area(device->device_ctx_area);