diff options
Diffstat (limited to 'Kernel/Devices')
-rw-r--r-- | Kernel/Devices/BlockDevice.cpp | 14 | ||||
-rw-r--r-- | Kernel/Devices/Device.h | 4 |
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); |