From 2a5d9a6944a71a44fe5e25a6d891b35f2be1a5e7 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Mon, 28 Jun 2021 15:19:25 +0200 Subject: [PATCH] Kernel: Fix `adopt_ref_if_nonnull(new T).release_nonnull()` pattern This does the exact thing as `adopt_ref`, which is a recent addition to AK. Note that pointers returned by a bare new (without `nothrow`) are guaranteed not to return null, so they can safely be converted into references. --- Kernel/Devices/FullDevice.cpp | 3 +-- Kernel/Devices/MemoryDevice.cpp | 2 +- Kernel/Devices/RandomDevice.cpp | 2 +- Kernel/Devices/ZeroDevice.cpp | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index fec5cc50c9..852a4fa50e 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -15,7 +15,7 @@ namespace Kernel { UNMAP_AFTER_INIT NonnullRefPtr FullDevice::must_create() { - return adopt_ref_if_nonnull(new FullDevice).release_nonnull(); + return adopt_ref(*new FullDevice); } UNMAP_AFTER_INIT FullDevice::FullDevice() @@ -45,5 +45,4 @@ KResultOr FullDevice::write(FileDescription&, u64, const UserOrKernelBuf return 0; return ENOSPC; } - } diff --git a/Kernel/Devices/MemoryDevice.cpp b/Kernel/Devices/MemoryDevice.cpp index 4a7ee97e56..6955a6dc34 100644 --- a/Kernel/Devices/MemoryDevice.cpp +++ b/Kernel/Devices/MemoryDevice.cpp @@ -17,7 +17,7 @@ namespace Kernel { UNMAP_AFTER_INIT NonnullRefPtr MemoryDevice::must_create() { - return adopt_ref_if_nonnull(new MemoryDevice).release_nonnull(); + return adopt_ref(*new MemoryDevice); } UNMAP_AFTER_INIT MemoryDevice::MemoryDevice() diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index 302ab4a00b..538e91ac37 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -13,7 +13,7 @@ namespace Kernel { UNMAP_AFTER_INIT NonnullRefPtr RandomDevice::must_create() { - return adopt_ref_if_nonnull(new RandomDevice).release_nonnull(); + return adopt_ref(*new RandomDevice); } UNMAP_AFTER_INIT RandomDevice::RandomDevice() diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index 37324d2376..e2c7908a4f 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -14,7 +14,7 @@ namespace Kernel { UNMAP_AFTER_INIT NonnullRefPtr ZeroDevice::must_create() { - return adopt_ref_if_nonnull(new ZeroDevice).release_nonnull(); + return adopt_ref(*new ZeroDevice); } UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()