USB: Add nullpointer checks to USB Device destructor

It seems to be possible that in case of USB issues a Device
is destroyed before it is registered with the device manager.
In such a case fNode of the device is NULL and there is a
page fault followed by a panic.

Fixes #18922.

Change-Id: I0a363a0ff85e6a74788701738e0cb85a90e99a05
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7821
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Timm Steinbeck
2024-06-29 15:28:46 +00:00
committed by waddlesplash
parent 722d3c01b7
commit 922624afa6
@@ -341,10 +341,12 @@ Device::~Device()
// though, since we may be deleted because the device was unplugged already.
Unconfigure(false);
status_t error = gDeviceManager->unregister_node(fNode);
if (error != B_OK && error != B_BUSY)
TRACE_ERROR("failed to unregister device node\n");
fNode = NULL;
if (fNode != NULL) {
status_t error = gDeviceManager->unregister_node(fNode);
if (error != B_OK && error != B_BUSY)
TRACE_ERROR("failed to unregister device node\n");
fNode = NULL;
}
// Destroy all Interfaces in the Configurations hierarchy.
for (int32 i = 0; fConfigurations != NULL