summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-06-28 15:19:25 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-29 22:57:52 +0430
commit2a5d9a6944a71a44fe5e25a6d891b35f2be1a5e7 (patch)
treeda7d4474c765d458e97221378f476b2878c2ea9c
parent9b1157924b78ab2d4c4817a42591085e5de9afc8 (diff)
downloadserenity-2a5d9a6944a71a44fe5e25a6d891b35f2be1a5e7.zip
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.
-rw-r--r--Kernel/Devices/FullDevice.cpp3
-rw-r--r--Kernel/Devices/MemoryDevice.cpp2
-rw-r--r--Kernel/Devices/RandomDevice.cpp2
-rw-r--r--Kernel/Devices/ZeroDevice.cpp2
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> 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<size_t> 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> 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> 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> ZeroDevice::must_create()
{
- return adopt_ref_if_nonnull(new ZeroDevice).release_nonnull();
+ return adopt_ref(*new ZeroDevice);
}
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()