diff options
author | Pankaj Raghav <dev@pankajraghav.com> | 2023-05-17 19:23:03 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-19 22:04:37 +0200 |
commit | 489e268b9669865a9b03efcf5d1393b2861a5aad (patch) | |
tree | 397edaad90009c13c401308f9760614ab7cc5688 /Kernel/Memory | |
parent | 4617c05a08a41ad8c478b10ad27601fedd6ccb62 (diff) | |
download | serenity-489e268b9669865a9b03efcf5d1393b2861a5aad.zip |
Kernel/ScatterGatherList: Return ErrorOr from try_create
This removes the TODO from the try_create API to return ErrorOr. This
is also a preparation patch to move the init code in the constructor
that can fail to this try_create function.
Diffstat (limited to 'Kernel/Memory')
-rw-r--r-- | Kernel/Memory/ScatterGatherList.cpp | 10 | ||||
-rw-r--r-- | Kernel/Memory/ScatterGatherList.h | 2 |
2 files changed, 4 insertions, 8 deletions
diff --git a/Kernel/Memory/ScatterGatherList.cpp b/Kernel/Memory/ScatterGatherList.cpp index 1eb9b6e53b..f49237c2d9 100644 --- a/Kernel/Memory/ScatterGatherList.cpp +++ b/Kernel/Memory/ScatterGatherList.cpp @@ -8,14 +8,10 @@ namespace Kernel::Memory { -LockRefPtr<ScatterGatherList> ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size) +ErrorOr<LockRefPtr<ScatterGatherList>> ScatterGatherList::try_create(AsyncBlockDeviceRequest& request, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size) { - auto maybe_vm_object = AnonymousVMObject::try_create_with_physical_pages(allocated_pages); - if (maybe_vm_object.is_error()) { - // FIXME: Would be nice to be able to return a ErrorOr here. - return {}; - } - return adopt_lock_ref_if_nonnull(new (nothrow) ScatterGatherList(maybe_vm_object.release_value(), request, device_block_size)); + auto vm_object = TRY(AnonymousVMObject::try_create_with_physical_pages(allocated_pages)); + return adopt_lock_ref_if_nonnull(new (nothrow) ScatterGatherList(vm_object, request, device_block_size)); } ScatterGatherList::ScatterGatherList(NonnullLockRefPtr<AnonymousVMObject> vm_object, AsyncBlockDeviceRequest& request, size_t device_block_size) diff --git a/Kernel/Memory/ScatterGatherList.h b/Kernel/Memory/ScatterGatherList.h index bcd2e496ce..d6920f025b 100644 --- a/Kernel/Memory/ScatterGatherList.h +++ b/Kernel/Memory/ScatterGatherList.h @@ -19,7 +19,7 @@ namespace Kernel::Memory { class ScatterGatherList final : public AtomicRefCounted<ScatterGatherList> { public: - static LockRefPtr<ScatterGatherList> try_create(AsyncBlockDeviceRequest&, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size); + static ErrorOr<LockRefPtr<ScatterGatherList>> try_create(AsyncBlockDeviceRequest&, Span<NonnullRefPtr<PhysicalPage>> allocated_pages, size_t device_block_size); VMObject const& vmobject() const { return m_vm_object; } VirtualAddress dma_region() const { return m_dma_region->vaddr(); } size_t scatters_count() const { return m_vm_object->physical_pages().size(); } |