From 0f22ba5bf2a1393ac011ad4d09aa0cefce946be9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 17 Nov 2021 15:44:58 +0100 Subject: [PATCH] AK: Make RedBlackTree::try_insert() return ErrorOr instead of bool --- AK/RedBlackTree.h | 10 +++++----- Kernel/Memory/AddressSpace.cpp | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/AK/RedBlackTree.h b/AK/RedBlackTree.h index 1734f83997e..713888f7f46 100644 --- a/AK/RedBlackTree.h +++ b/AK/RedBlackTree.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -453,19 +454,18 @@ public: insert(key, V(value)); } - [[nodiscard]] bool try_insert(K key, V&& value) + ErrorOr try_insert(K key, V&& value) { auto* node = new (nothrow) Node(key, move(value)); if (!node) - return false; + return Error::from_errno(ENOMEM); BaseTree::insert(node); - return true; + return {}; } void insert(K key, V&& value) { - auto success = try_insert(key, move(value)); - VERIFY(success); + MUST(try_insert(key, move(value))); } using Iterator = RedBlackTreeIterator; diff --git a/Kernel/Memory/AddressSpace.cpp b/Kernel/Memory/AddressSpace.cpp index 6f3e54d313d..d936be2b402 100644 --- a/Kernel/Memory/AddressSpace.cpp +++ b/Kernel/Memory/AddressSpace.cpp @@ -267,8 +267,7 @@ ErrorOr AddressSpace::add_region(NonnullOwnPtr region) { auto* ptr = region.ptr(); SpinlockLocker lock(m_lock); - if (!m_regions.try_insert(region->vaddr().get(), move(region))) - return ENOMEM; + TRY(m_regions.try_insert(region->vaddr().get(), move(region))); return ptr; }