Skip to content

Commit 4aad509

Browse files
committed
Kernel: Propagate errors in USBManagement::register_driver()
We currently don't support loadable modules, so all callers of this function use `MUST()` on the result for now.
1 parent 601a97d commit 4aad509

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

Kernel/Bus/USB/Drivers/HID.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ USB_DEVICE_DRIVER(HIDDriver);
9191
void HIDDriver::init()
9292
{
9393
auto driver = MUST(adopt_nonnull_lock_ref_or_enomem(new (nothrow) HIDDriver()));
94-
USBManagement::register_driver(driver);
94+
MUST(USBManagement::register_driver(driver));
9595
}
9696

9797
static constexpr u8 DESCRIPTOR_TYPE_HID = 0x21;

Kernel/Bus/USB/Drivers/MassStorage/MassStorageDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ USB_DEVICE_DRIVER(MassStorageDriver);
2323
void MassStorageDriver::init()
2424
{
2525
auto driver = MUST(adopt_nonnull_lock_ref_or_enomem(new MassStorageDriver()));
26-
USBManagement::register_driver(driver);
26+
MUST(USBManagement::register_driver(driver));
2727
}
2828

2929
ErrorOr<void> MassStorageDriver::probe(USB::Device& device)

Kernel/Bus/USB/USBManagement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ UNMAP_AFTER_INIT USBManagement::USBManagement()
2020
SysFSUSBBusDirectory::initialize();
2121
}
2222

23-
void USBManagement::register_driver(NonnullLockRefPtr<Driver> driver)
23+
ErrorOr<void> USBManagement::register_driver(NonnullLockRefPtr<Driver> driver)
2424
{
2525
dbgln_if(USB_DEBUG, "Registering driver {}", driver->name());
26-
s_available_drivers->append(driver);
26+
return s_available_drivers->try_append(driver);
2727
}
2828

2929
LockRefPtr<Driver> USBManagement::get_driver_by_name(StringView name)

Kernel/Bus/USB/USBManagement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class USBManagement {
1919
USBManagement();
2020
static USBManagement& the();
2121

22-
static void register_driver(NonnullLockRefPtr<Driver> driver);
22+
static ErrorOr<void> register_driver(NonnullLockRefPtr<Driver> driver);
2323
static LockRefPtr<Driver> get_driver_by_name(StringView name);
2424
static void unregister_driver(NonnullLockRefPtr<Driver> driver);
2525

0 commit comments

Comments
 (0)