diff --git a/Kernel/Bus/USB/SysFSUSB.cpp b/Kernel/Bus/USB/SysFSUSB.cpp index 4448f3b48e..27842eab57 100644 --- a/Kernel/Bus/USB/SysFSUSB.cpp +++ b/Kernel/Bus/USB/SysFSUSB.cpp @@ -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(*this).output(builder)) diff --git a/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp b/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp index 4140815650..2f65a49275 100644 --- a/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIRootHub.cpp @@ -85,11 +85,7 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = { KResultOr> UHCIRootHub::try_create(NonnullRefPtr 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 uhci_controller) diff --git a/Kernel/Bus/USB/USBDevice.cpp b/Kernel/Bus/USB/USBDevice.cpp index 4ad6d78608..44228eb84f 100644 --- a/Kernel/Bus/USB/USBDevice.cpp +++ b/Kernel/Bus/USB/USBDevice.cpp @@ -19,14 +19,9 @@ namespace Kernel::USB { KResultOr> 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(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 default_pipe) diff --git a/Kernel/Bus/USB/USBPipe.cpp b/Kernel/Bus/USB/USBPipe.cpp index 97efb8e8e4..dd6d358a1c 100644 --- a/Kernel/Bus/USB/USBPipe.cpp +++ b/Kernel/Bus/USB/USBPipe.cpp @@ -13,11 +13,7 @@ namespace Kernel::USB { KResultOr> 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)