summaryrefslogtreecommitdiff
path: root/Kernel/Devices
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 16:40:54 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 16:42:03 +0200
commit9669bf29f61591990f26688ae5cdd331bd5c6fa1 (patch)
treed10218ea56e4db61110892884fe555c2765867ed /Kernel/Devices
parenta01b19c878f7c6971d1ffbde039d4792e7446990 (diff)
downloadserenity-9669bf29f61591990f26688ae5cdd331bd5c6fa1.zip
Kernel: Make Device request creation return KResultOr
This allows us to propagate errors in a bunch of new places.
Diffstat (limited to 'Kernel/Devices')
-rw-r--r--Kernel/Devices/BlockDevice.cpp14
-rw-r--r--Kernel/Devices/Device.h4
2 files changed, 14 insertions, 4 deletions
diff --git a/Kernel/Devices/BlockDevice.cpp b/Kernel/Devices/BlockDevice.cpp
index 094692ab3d..524b7ee951 100644
--- a/Kernel/Devices/BlockDevice.cpp
+++ b/Kernel/Devices/BlockDevice.cpp
@@ -30,7 +30,12 @@ BlockDevice::~BlockDevice()
bool BlockDevice::read_block(u64 index, UserOrKernelBuffer& buffer)
{
- auto read_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, 1, buffer, 512);
+ auto read_request_or_error = try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, 1, buffer, 512);
+ if (read_request_or_error.is_error()) {
+ dbgln("BlockDevice::read_block({}): try_make_request failed", index);
+ return false;
+ }
+ auto read_request = read_request_or_error.release_value();
switch (read_request->wait().request_result()) {
case AsyncDeviceRequest::Success:
return true;
@@ -51,7 +56,12 @@ bool BlockDevice::read_block(u64 index, UserOrKernelBuffer& buffer)
bool BlockDevice::write_block(u64 index, const UserOrKernelBuffer& buffer)
{
- auto write_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, 1, buffer, 512);
+ auto write_request_or_error = try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, 1, buffer, 512);
+ if (write_request_or_error.is_error()) {
+ dbgln("BlockDevice::write_block({}): try_make_request failed", index);
+ return false;
+ }
+ auto write_request = write_request_or_error.release_value();
switch (write_request->wait().request_result()) {
case AsyncDeviceRequest::Success:
return true;
diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h
index e39b4e80e4..776dfa2dac 100644
--- a/Kernel/Devices/Device.h
+++ b/Kernel/Devices/Device.h
@@ -48,9 +48,9 @@ public:
void process_next_queued_request(Badge<AsyncDeviceRequest>, const AsyncDeviceRequest&);
template<typename AsyncRequestType, typename... Args>
- NonnullRefPtr<AsyncRequestType> make_request(Args&&... args)
+ KResultOr<NonnullRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
{
- auto request = adopt_ref(*new AsyncRequestType(*this, forward<Args>(args)...));
+ auto request = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AsyncRequestType(*this, forward<Args>(args)...)));
SpinlockLocker lock(m_requests_lock);
bool was_empty = m_requests.is_empty();
m_requests.append(request);