Kernel/USB: Use TRY() and adopt_nonnull_own_or_enomem() some more

This commit is contained in:
Andreas Kling 2021-09-06 12:03:13 +02:00
parent e3b063581e
commit f173f73f10
4 changed files with 5 additions and 20 deletions

View file

@ -52,9 +52,7 @@ KResult SysFSUSBDeviceInformation::refresh_data(FileDescription& description) co
MutexLocker lock(m_lock);
auto& cached_data = description.data();
if (!cached_data) {
cached_data = adopt_own_if_nonnull(new (nothrow) SysFSInodeData);
if (!cached_data)
return ENOMEM;
cached_data = TRY(adopt_nonnull_own_or_enomem(new (nothrow) SysFSInodeData));
}
KBufferBuilder builder;
if (!const_cast<SysFSUSBDeviceInformation&>(*this).output(builder))

View file

@ -85,11 +85,7 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = {
KResultOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
{
auto root_hub = adopt_own_if_nonnull(new (nothrow) UHCIRootHub(uhci_controller));
if (!root_hub)
return ENOMEM;
return root_hub.release_nonnull();
return adopt_nonnull_own_or_enomem(new (nothrow) UHCIRootHub(uhci_controller));
}
UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller)

View file

@ -19,14 +19,9 @@ namespace Kernel::USB {
KResultOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
{
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
auto device = try_make_ref_counted<Device>(controller, port, speed, move(pipe));
if (!device)
return ENOMEM;
auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe))));
TRY(device->enumerate_device());
return device.release_nonnull();
return device;
}
Device::Device(USBController const& controller, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe)

View file

@ -13,11 +13,7 @@ namespace Kernel::USB {
KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(USBController const& controller, Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
{
auto pipe = adopt_own_if_nonnull(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
if (!pipe)
return ENOMEM;
return pipe.release_nonnull();
return adopt_nonnull_own_or_enomem(new (nothrow) Pipe(controller, type, direction, endpoint_address, max_packet_size, poll_interval, device_address));
}
Pipe::Pipe(USBController const& controller, Type type, Pipe::Direction direction, u16 max_packet_size)