summaryrefslogtreecommitdiff
path: root/Kernel/Bus/USB
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-06 00:18:32 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-06 01:55:27 +0200
commit79fbad6df90021ae7388d4207c7409e2bcc4a261 (patch)
tree143a6d9a2ae01304cc4916ec83b902d88675dfdf /Kernel/Bus/USB
parentf4a9a0d5612d790462192f3cfff29b4dd40bbff0 (diff)
downloadserenity-79fbad6df90021ae7388d4207c7409e2bcc4a261.zip
Kernel/USB: Tidy up USB::Transfer construction
Diffstat (limited to 'Kernel/Bus/USB')
-rw-r--r--Kernel/Bus/USB/USBPipe.cpp6
-rw-r--r--Kernel/Bus/USB/USBTransfer.cpp6
-rw-r--r--Kernel/Bus/USB/USBTransfer.h2
3 files changed, 5 insertions, 9 deletions
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<size_t> 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> Transfer::try_create(Pipe& pipe, u16 len)
+KResultOr<NonnullRefPtr<Transfer>> 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<Transfer>(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<Memory::Region> 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<Transfer> {
public:
- static RefPtr<Transfer> try_create(Pipe& pipe, u16 len);
+ static KResultOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length);
public:
Transfer() = delete;