mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
Kernel: Don't register USB devices if USBManagement is not initialized
This commit is contained in:
parent
639051d34e
commit
91816c15f8
4 changed files with 16 additions and 9 deletions
|
@ -20,7 +20,7 @@ USB_DEVICE_DRIVER(MouseDriver);
|
|||
void MouseDriver::init()
|
||||
{
|
||||
auto driver = MUST(adopt_nonnull_lock_ref_or_enomem(new MouseDriver()));
|
||||
USBManagement::the().register_driver(driver);
|
||||
USBManagement::register_driver(driver);
|
||||
}
|
||||
|
||||
ErrorOr<void> MouseDriver::checkout_interface(USB::Device& device, USBInterface const& interface)
|
||||
|
|
|
@ -24,7 +24,7 @@ USB_DEVICE_DRIVER(MassStorageDriver);
|
|||
void MassStorageDriver::init()
|
||||
{
|
||||
auto driver = MUST(adopt_nonnull_lock_ref_or_enomem(new MassStorageDriver()));
|
||||
USBManagement::the().register_driver(driver);
|
||||
USBManagement::register_driver(driver);
|
||||
}
|
||||
|
||||
ErrorOr<void> MassStorageDriver::checkout_interface(USB::Device& device, USBInterface const& interface)
|
||||
|
|
|
@ -81,22 +81,29 @@ UNMAP_AFTER_INIT void USBManagement::initialize()
|
|||
|
||||
void USBManagement::register_driver(NonnullLockRefPtr<Driver> driver)
|
||||
{
|
||||
if (!initialized())
|
||||
return;
|
||||
dbgln_if(USB_DEBUG, "Registering driver {}", driver->name());
|
||||
m_available_drivers.append(driver);
|
||||
the().m_available_drivers.append(driver);
|
||||
}
|
||||
|
||||
LockRefPtr<Driver> USBManagement::get_driver_by_name(StringView name)
|
||||
{
|
||||
auto it = m_available_drivers.find_if([name](auto driver) { return driver->name() == name; });
|
||||
if (!initialized())
|
||||
return nullptr;
|
||||
auto it = the().m_available_drivers.find_if([name](auto driver) { return driver->name() == name; });
|
||||
return it.is_end() ? nullptr : LockRefPtr { *it };
|
||||
}
|
||||
|
||||
void USBManagement::unregister_driver(NonnullLockRefPtr<Driver> driver)
|
||||
{
|
||||
if (!initialized())
|
||||
return;
|
||||
auto& the_instance = the();
|
||||
dbgln_if(USB_DEBUG, "Unregistering driver {}", driver->name());
|
||||
auto const& found_driver = m_available_drivers.find(driver);
|
||||
auto const& found_driver = the_instance.m_available_drivers.find(driver);
|
||||
if (!found_driver.is_end())
|
||||
m_available_drivers.remove(found_driver.index());
|
||||
the_instance.m_available_drivers.remove(found_driver.index());
|
||||
}
|
||||
|
||||
USBManagement& USBManagement::the()
|
||||
|
|
|
@ -21,9 +21,9 @@ public:
|
|||
static void initialize();
|
||||
static USBManagement& the();
|
||||
|
||||
void register_driver(NonnullLockRefPtr<Driver> driver);
|
||||
LockRefPtr<Driver> get_driver_by_name(StringView name);
|
||||
void unregister_driver(NonnullLockRefPtr<Driver> driver);
|
||||
static void register_driver(NonnullLockRefPtr<Driver> driver);
|
||||
static LockRefPtr<Driver> get_driver_by_name(StringView name);
|
||||
static void unregister_driver(NonnullLockRefPtr<Driver> driver);
|
||||
|
||||
Vector<NonnullLockRefPtr<Driver>>& available_drivers() { return m_available_drivers; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue