diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-07 12:09:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 13:53:14 +0200 |
commit | b4811324183cc64bd671f93c889fa5e6590e0182 (patch) | |
tree | 083ec95329a20fbcf74f78ce8ea2bf3c9a4055b8 /Kernel/Storage | |
parent | 7bf88444993a72f588ce3bd849042c3420e222a7 (diff) | |
download | serenity-b4811324183cc64bd671f93c889fa5e6590e0182.zip |
Kernel: Make UserOrKernelBuffer return KResult from read/write/memset
This allows us to simplify a whole bunch of call sites with TRY(). :^)
Diffstat (limited to 'Kernel/Storage')
-rw-r--r-- | Kernel/Storage/AHCIPort.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/BMIDEChannel.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/RamdiskDevice.cpp | 10 | ||||
-rw-r--r-- | Kernel/Storage/StorageDevice.cpp | 6 |
4 files changed, 10 insertions, 14 deletions
diff --git a/Kernel/Storage/AHCIPort.cpp b/Kernel/Storage/AHCIPort.cpp index cde1054c21..9840a78da4 100644 --- a/Kernel/Storage/AHCIPort.cpp +++ b/Kernel/Storage/AHCIPort.cpp @@ -103,7 +103,7 @@ void AHCIPort::handle_interrupt() VERIFY(m_current_request); VERIFY(m_current_scatter_list); if (m_current_request->request_type() == AsyncBlockDeviceRequest::Read) { - if (!m_current_request->write_to_buffer(m_current_request->buffer(), m_current_scatter_list->dma_region().as_ptr(), m_connected_device->block_size() * m_current_request->block_count())) { + if (auto result = m_current_request->write_to_buffer(m_current_request->buffer(), m_current_scatter_list->dma_region().as_ptr(), m_connected_device->block_size() * m_current_request->block_count()); result.is_error()) { dbgln_if(AHCI_DEBUG, "AHCI Port {}: Request failure, memory fault occurred when reading in data.", representative_port_index()); m_current_scatter_list = nullptr; complete_current_request(AsyncDeviceRequest::MemoryFault); @@ -445,7 +445,7 @@ Optional<AsyncDeviceRequest::RequestResult> AHCIPort::prepare_and_set_scatter_li if (!m_current_scatter_list) return AsyncDeviceRequest::Failure; if (request.request_type() == AsyncBlockDeviceRequest::Write) { - if (!request.read_from_buffer(request.buffer(), m_current_scatter_list->dma_region().as_ptr(), m_connected_device->block_size() * request.block_count())) { + if (auto result = request.read_from_buffer(request.buffer(), m_current_scatter_list->dma_region().as_ptr(), m_connected_device->block_size() * request.block_count()); result.is_error()) { return AsyncDeviceRequest::MemoryFault; } } diff --git a/Kernel/Storage/BMIDEChannel.cpp b/Kernel/Storage/BMIDEChannel.cpp index dbebb611cd..732b8baa41 100644 --- a/Kernel/Storage/BMIDEChannel.cpp +++ b/Kernel/Storage/BMIDEChannel.cpp @@ -135,7 +135,7 @@ void BMIDEChannel::complete_current_request(AsyncDeviceRequest::RequestResult re if (result == AsyncDeviceRequest::Success) { if (current_request->request_type() == AsyncBlockDeviceRequest::Read) { - if (!current_request->write_to_buffer(current_request->buffer(), m_dma_buffer_region->vaddr().as_ptr(), 512 * current_request->block_count())) { + if (auto result = current_request->write_to_buffer(current_request->buffer(), m_dma_buffer_region->vaddr().as_ptr(), 512 * current_request->block_count()); result.is_error()) { lock.unlock(); current_request->complete(AsyncDeviceRequest::MemoryFault); return; @@ -164,7 +164,7 @@ void BMIDEChannel::ata_write_sectors(bool slave_request, u16 capabilities) prdt().offset = m_dma_buffer_page->paddr().get(); prdt().size = 512 * m_current_request->block_count(); - if (!m_current_request->read_from_buffer(m_current_request->buffer(), m_dma_buffer_region->vaddr().as_ptr(), 512 * m_current_request->block_count())) { + if (auto result = m_current_request->read_from_buffer(m_current_request->buffer(), m_dma_buffer_region->vaddr().as_ptr(), 512 * m_current_request->block_count()); result.is_error()) { complete_current_request(AsyncDeviceRequest::MemoryFault); return; } diff --git a/Kernel/Storage/RamdiskDevice.cpp b/Kernel/Storage/RamdiskDevice.cpp index 8b962df4d6..76cf6c7fd3 100644 --- a/Kernel/Storage/RamdiskDevice.cpp +++ b/Kernel/Storage/RamdiskDevice.cpp @@ -45,15 +45,13 @@ void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request) if ((offset + length > base + size) || (offset + length < base)) { request.complete(AsyncDeviceRequest::Failure); } else { - bool success; - + auto result = KResult(KSuccess); if (request.request_type() == AsyncBlockDeviceRequest::Read) { - success = request.buffer().write(offset, length); + result = request.buffer().write(offset, length); } else { - success = request.buffer().read(offset, length); + result = request.buffer().read(offset, length); } - - request.complete(success ? AsyncDeviceRequest::Success : AsyncDeviceRequest::MemoryFault); + request.complete(result.is_success() ? AsyncDeviceRequest::Success : AsyncDeviceRequest::MemoryFault); } } diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp index abdfb33104..f5cf6c83dd 100644 --- a/Kernel/Storage/StorageDevice.cpp +++ b/Kernel/Storage/StorageDevice.cpp @@ -93,8 +93,7 @@ KResultOr<size_t> StorageDevice::read(FileDescription&, u64 offset, UserOrKernel default: break; } - if (!outbuf.write(data.data(), pos, remaining)) - return EFAULT; + TRY(outbuf.write(data.data(), pos, remaining)); } return pos + remaining; @@ -166,8 +165,7 @@ KResultOr<size_t> StorageDevice::write(FileDescription&, u64 offset, const UserO } } - if (!inbuf.read(data.data(), pos, remaining)) - return EFAULT; + TRY(inbuf.read(data.data(), pos, remaining)); { auto write_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index + whole_blocks, 1, data_buffer, block_size()); |