mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
Kernel: Use try_create
not must_create
in SysFSUSB::create
The function `KString::must_create()` can only be enforced during early boot (that is, when `g_in_early_boot` is true), hence the use of this function during runtime causes a `VERIFY` to assert, leading to a Kernel Panic. We should instead use `TRY()` along with `try_create()` to prevent this from crashing whenever a USB device is inserted into the system, and we don't have enough memory to allocate the device's KString.
This commit is contained in:
parent
1d7d7d39b7
commit
af31253a16
2 changed files with 11 additions and 5 deletions
|
@ -133,7 +133,13 @@ void SysFSUSBBusDirectory::plug(USB::Device& new_device)
|
||||||
SpinlockLocker lock(m_lock);
|
SpinlockLocker lock(m_lock);
|
||||||
auto device_node = device_node_for(new_device);
|
auto device_node = device_node_for(new_device);
|
||||||
VERIFY(!device_node);
|
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)
|
void SysFSUSBBusDirectory::unplug(USB::Device& deleted_device)
|
||||||
|
@ -162,10 +168,10 @@ UNMAP_AFTER_INIT void SysFSUSBBusDirectory::initialize()
|
||||||
s_procfs_usb_bus_directory = directory;
|
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()));
|
auto device_name = TRY(KString::try_create(String::number(device.address())));
|
||||||
return adopt_ref(*new SysFSUSBDeviceInformation(move(device_name), device));
|
return adopt_nonnull_ref_or_enomem(new (nothrow) SysFSUSBDeviceInformation(move(device_name), device));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SysFSUSBDeviceInformation : public SysFSComponent {
|
||||||
public:
|
public:
|
||||||
virtual ~SysFSUSBDeviceInformation() override;
|
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(); }
|
virtual StringView name() const override { return m_device_name->view(); }
|
||||||
|
|
||||||
RefPtr<USB::Device> device() const { return m_device; }
|
RefPtr<USB::Device> device() const { return m_device; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue