From a182f19364351a88c75aca671052c702c7c0eaf2 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 19 Feb 2019 17:14:54 -0500 Subject: [PATCH] USB: Properly assign IDs to USB Bus Managers (HCI drivers). Previously they would just get -1, as the BusManager class would request their ID before they had been added to the Stack. Now we add them to the stack inside ::Start(), rather than letting the individual drivers do that just after ::Start(), and then assign the ID there directly. --- src/add-ons/kernel/bus_managers/usb/BusManager.cpp | 4 +++- src/add-ons/kernel/busses/usb/ehci.cpp | 6 ++++-- src/add-ons/kernel/busses/usb/ohci.cpp | 6 ++++-- src/add-ons/kernel/busses/usb/uhci.cpp | 6 ++++-- src/add-ons/kernel/busses/usb/xhci.cpp | 6 ++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/usb/BusManager.cpp b/src/add-ons/kernel/bus_managers/usb/BusManager.cpp index 99f7953866..f6305802c7 100644 --- a/src/add-ons/kernel/bus_managers/usb/BusManager.cpp +++ b/src/add-ons/kernel/bus_managers/usb/BusManager.cpp @@ -14,7 +14,7 @@ BusManager::BusManager(Stack *stack) : fInitOK(false), fStack(stack), fRootHub(NULL), - fUSBID(fStack->IndexOfBusManager(this)) + fUSBID((uint32)-1) { mutex_init(&fLock, "usb busmanager lock"); @@ -253,6 +253,8 @@ BusManager::FreeDevice(Device *device) status_t BusManager::Start() { + fStack->AddBusManager(this); + fUSBID = fStack->IndexOfBusManager(this); return B_OK; } diff --git a/src/add-ons/kernel/busses/usb/ehci.cpp b/src/add-ons/kernel/busses/usb/ehci.cpp index b45541ea46..9c6bd23a85 100644 --- a/src/add-ons/kernel/busses/usb/ehci.cpp +++ b/src/add-ons/kernel/busses/usb/ehci.cpp @@ -1216,8 +1216,10 @@ EHCI::AddTo(Stack *stack) // the bus took it away item = new(std::nothrow) pci_info; - bus->Start(); - stack->AddBusManager(bus); + if (bus->Start() != B_OK) { + delete bus; + continue; + } found = true; } } diff --git a/src/add-ons/kernel/busses/usb/ohci.cpp b/src/add-ons/kernel/busses/usb/ohci.cpp index 7bf1513b30..ded588e16a 100644 --- a/src/add-ons/kernel/busses/usb/ohci.cpp +++ b/src/add-ons/kernel/busses/usb/ohci.cpp @@ -647,8 +647,10 @@ OHCI::AddTo(Stack *stack) // the bus took it away item = new(std::nothrow) pci_info; - bus->Start(); - stack->AddBusManager(bus); + if (bus->Start() != B_OK) { + delete bus; + continue; + } found = true; } } diff --git a/src/add-ons/kernel/busses/usb/uhci.cpp b/src/add-ons/kernel/busses/usb/uhci.cpp index 8d6f4e361c..ade4ca7114 100644 --- a/src/add-ons/kernel/busses/usb/uhci.cpp +++ b/src/add-ons/kernel/busses/usb/uhci.cpp @@ -1923,8 +1923,10 @@ UHCI::AddTo(Stack *stack) // the bus took it away item = new(std::nothrow) pci_info; - bus->Start(); - stack->AddBusManager(bus); + if (bus->Start() != B_OK) { + delete bus; + continue; + } found = true; } } diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp b/src/add-ons/kernel/busses/usb/xhci.cpp index b6cf4b13fd..07382ccc5f 100644 --- a/src/add-ons/kernel/busses/usb/xhci.cpp +++ b/src/add-ons/kernel/busses/usb/xhci.cpp @@ -864,8 +864,10 @@ XHCI::AddTo(Stack *stack) // the bus took it away item = new(std::nothrow) pci_info; - bus->Start(); - stack->AddBusManager(bus); + if (bus->Start() != B_OK) { + delete bus; + continue; + } found = true; } }