summaryrefslogtreecommitdiff
path: root/Kernel/Memory
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 12:09:52 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 13:53:14 +0200
commitb4811324183cc64bd671f93c889fa5e6590e0182 (patch)
tree083ec95329a20fbcf74f78ce8ea2bf3c9a4055b8 /Kernel/Memory
parent7bf88444993a72f588ce3bd849042c3420e222a7 (diff)
downloadserenity-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/Memory')
-rw-r--r--Kernel/Memory/RingBuffer.cpp14
1 files changed, 6 insertions, 8 deletions
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<size_t> 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;
}