diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 22:39:43 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 01:55:27 +0200 |
commit | 21f7932ae23eba1cb72e8172ccd3b2936f4e24f8 (patch) | |
tree | a01091aef6c328873463cc3ef38590e28b806641 /Kernel/Memory | |
parent | 52cbbe1dc534feb7a8f5813ef07ade242873d794 (diff) | |
download | serenity-21f7932ae23eba1cb72e8172ccd3b2936f4e24f8.zip |
Kernel: Use TRY() and adopt_nonnull_ref_or_enomem() in AnonymousVMObject
Diffstat (limited to 'Kernel/Memory')
-rw-r--r-- | Kernel/Memory/AnonymousVMObject.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/Kernel/Memory/AnonymousVMObject.cpp b/Kernel/Memory/AnonymousVMObject.cpp index e57612987c..1857daeb04 100644 --- a/Kernel/Memory/AnonymousVMObject.cpp +++ b/Kernel/Memory/AnonymousVMObject.cpp @@ -42,14 +42,8 @@ KResultOr<NonnullRefPtr<VMObject>> AnonymousVMObject::try_clone() // one would keep the one it still has. This ensures that the original // one and this one, as well as the clone have sufficient resources // to cow all pages as needed - auto new_shared_committed_cow_pages = try_make_ref_counted<SharedCommittedCowPages>(move(committed_pages)); - if (!new_shared_committed_cow_pages) - return ENOMEM; - - auto maybe_clone = adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(*this, *new_shared_committed_cow_pages)); - if (!maybe_clone) - return ENOMEM; - auto clone = maybe_clone.release_nonnull(); + auto new_shared_committed_cow_pages = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedCommittedCowPages(move(committed_pages)))); + auto clone = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousVMObject(*this, *new_shared_committed_cow_pages))); m_shared_committed_cow_pages = move(new_shared_committed_cow_pages); @@ -98,12 +92,9 @@ KResultOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_purgea committed_pages = TRY(MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))); } - auto vmobject = adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, strategy, move(committed_pages))); - if (!vmobject) - return ENOMEM; - + auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousVMObject(size, strategy, move(committed_pages)))); vmobject->m_purgeable = true; - return vmobject.release_nonnull(); + return vmobject; } KResultOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>> physical_pages) |