diff options
Diffstat (limited to 'Kernel/Bus')
-rw-r--r-- | Kernel/Bus/USB/SysFSUSB.cpp | 14 | ||||
-rw-r--r-- | Kernel/Bus/USB/SysFSUSB.h | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/Kernel/Bus/USB/SysFSUSB.cpp b/Kernel/Bus/USB/SysFSUSB.cpp index e4fc0a67ef..f6faabed7c 100644 --- a/Kernel/Bus/USB/SysFSUSB.cpp +++ b/Kernel/Bus/USB/SysFSUSB.cpp @@ -133,7 +133,13 @@ void SysFSUSBBusDirectory::plug(USB::Device& new_device) SpinlockLocker lock(m_lock); auto device_node = device_node_for(new_device); VERIFY(!device_node); - m_device_nodes.append(SysFSUSBDeviceInformation::create(new_device)); + auto sysfs_usb_device_or_error = SysFSUSBDeviceInformation::create(new_device); + if (sysfs_usb_device_or_error.is_error()) { + dbgln("Failed to create SysFSUSBDevice for device id {}", new_device.address()); + return; + } + + m_device_nodes.append(sysfs_usb_device_or_error.release_value()); } void SysFSUSBBusDirectory::unplug(USB::Device& deleted_device) @@ -162,10 +168,10 @@ UNMAP_AFTER_INIT void SysFSUSBBusDirectory::initialize() s_procfs_usb_bus_directory = directory; } -NonnullRefPtr<SysFSUSBDeviceInformation> SysFSUSBDeviceInformation::create(USB::Device& device) +ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> SysFSUSBDeviceInformation::create(USB::Device& device) { - auto device_name = KString::must_create(String::number(device.address())); - return adopt_ref(*new SysFSUSBDeviceInformation(move(device_name), device)); + auto device_name = TRY(KString::try_create(String::number(device.address()))); + return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSUSBDeviceInformation(move(device_name), device)); } } diff --git a/Kernel/Bus/USB/SysFSUSB.h b/Kernel/Bus/USB/SysFSUSB.h index 87a5b8857e..bf7163dd76 100644 --- a/Kernel/Bus/USB/SysFSUSB.h +++ b/Kernel/Bus/USB/SysFSUSB.h @@ -19,7 +19,7 @@ class SysFSUSBDeviceInformation : public SysFSComponent { public: virtual ~SysFSUSBDeviceInformation() override; - static NonnullRefPtr<SysFSUSBDeviceInformation> create(USB::Device&); + static ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&); virtual StringView name() const override { return m_device_name->view(); } RefPtr<USB::Device> device() const { return m_device; } |