From 21f7932ae23eba1cb72e8172ccd3b2936f4e24f8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 5 Sep 2021 22:39:43 +0200 Subject: [PATCH] Kernel: Use TRY() and adopt_nonnull_ref_or_enomem() in AnonymousVMObject --- Kernel/Memory/AnonymousVMObject.cpp | 17 ++++------------- 1 file 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> 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(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> AnonymousVMObject::try_create_purgea committed_pages = TRY(MM.commit_user_physical_pages(ceil_div(size, static_cast(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> AnonymousVMObject::try_create_with_physical_pages(Span> physical_pages)