From b4811324183cc64bd671f93c889fa5e6590e0182 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 7 Sep 2021 12:09:52 +0200 Subject: Kernel: Make UserOrKernelBuffer return KResult from read/write/memset This allows us to simplify a whole bunch of call sites with TRY(). :^) --- Kernel/Memory/RingBuffer.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'Kernel/Memory/RingBuffer.cpp') diff --git a/Kernel/Memory/RingBuffer.cpp b/Kernel/Memory/RingBuffer.cpp index 96a82e54dc..06d2da02ff 100644 --- a/Kernel/Memory/RingBuffer.cpp +++ b/Kernel/Memory/RingBuffer.cpp @@ -22,20 +22,18 @@ bool RingBuffer::copy_data_in(const UserOrKernelBuffer& buffer, size_t offset, s bytes_copied = min(m_capacity_in_bytes - m_num_used_bytes, min(m_capacity_in_bytes - start_of_free_area, length)); if (bytes_copied == 0) return false; - if (buffer.read(m_region->vaddr().offset(start_of_free_area).as_ptr(), offset, bytes_copied)) { - m_num_used_bytes += bytes_copied; - start_of_copied_data = m_region->physical_page(start_of_free_area / PAGE_SIZE)->paddr().offset(start_of_free_area % PAGE_SIZE); - return true; - } - return false; + if (auto result = buffer.read(m_region->vaddr().offset(start_of_free_area).as_ptr(), offset, bytes_copied); result.is_error()) + return false; + m_num_used_bytes += bytes_copied; + start_of_copied_data = m_region->physical_page(start_of_free_area / PAGE_SIZE)->paddr().offset(start_of_free_area % PAGE_SIZE); + return true; } KResultOr RingBuffer::copy_data_out(size_t size, UserOrKernelBuffer& buffer) const { auto start = m_start_of_used % m_capacity_in_bytes; auto num_bytes = min(min(m_num_used_bytes, size), m_capacity_in_bytes - start); - if (!buffer.write(m_region->vaddr().offset(start).as_ptr(), num_bytes)) - return EIO; + TRY(buffer.write(m_region->vaddr().offset(start).as_ptr(), num_bytes)); return num_bytes; } -- cgit v1.2.3