From 79fbad6df90021ae7388d4207c7409e2bcc4a261 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Sep 2021 00:18:32 +0200 Subject: Kernel/USB: Tidy up USB::Transfer construction --- Kernel/Bus/USB/USBPipe.cpp | 6 +----- Kernel/Bus/USB/USBTransfer.cpp | 6 +++--- Kernel/Bus/USB/USBTransfer.h | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'Kernel/Bus/USB') diff --git a/Kernel/Bus/USB/USBPipe.cpp b/Kernel/Bus/USB/USBPipe.cpp index db404c8446..97efb8e8e4 100644 --- a/Kernel/Bus/USB/USBPipe.cpp +++ b/Kernel/Bus/USB/USBPipe.cpp @@ -61,11 +61,7 @@ KResultOr Pipe::control_transfer(u8 request_type, u8 request, u16 value, usb_request.index = index; usb_request.length = length; - auto transfer = Transfer::try_create(*this, length); - - if (!transfer) - return ENOMEM; - + auto transfer = TRY(Transfer::try_create(*this, length)); transfer->set_setup_packet(usb_request); dbgln_if(USB_DEBUG, "Pipe: Transfer allocated @ {}", transfer->buffer_physical()); diff --git a/Kernel/Bus/USB/USBTransfer.cpp b/Kernel/Bus/USB/USBTransfer.cpp index c940a5de11..642774f2c9 100644 --- a/Kernel/Bus/USB/USBTransfer.cpp +++ b/Kernel/Bus/USB/USBTransfer.cpp @@ -9,15 +9,15 @@ namespace Kernel::USB { -RefPtr Transfer::try_create(Pipe& pipe, u16 len) +KResultOr> Transfer::try_create(Pipe& pipe, u16 len) { // Initialize data buffer for transfer // This will definitely need to be refactored in the future, I doubt this will scale well... auto data_buffer = MM.allocate_kernel_region(PAGE_SIZE, "USB Transfer Buffer", Memory::Region::Access::ReadWrite); if (!data_buffer) - return {}; + return ENOMEM; - return try_make_ref_counted(pipe, len, data_buffer.release_nonnull()); + return adopt_nonnull_ref_or_enomem(new (nothrow) Transfer(pipe, len, data_buffer.release_nonnull())); } Transfer::Transfer(Pipe& pipe, u16 len, NonnullOwnPtr data_buffer) diff --git a/Kernel/Bus/USB/USBTransfer.h b/Kernel/Bus/USB/USBTransfer.h index 298bb38af7..35c342feb0 100644 --- a/Kernel/Bus/USB/USBTransfer.h +++ b/Kernel/Bus/USB/USBTransfer.h @@ -19,7 +19,7 @@ namespace Kernel::USB { class Transfer : public RefCounted { public: - static RefPtr try_create(Pipe& pipe, u16 len); + static KResultOr> try_create(Pipe&, u16 length); public: Transfer() = delete; -- cgit v1.2.3