mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
Kernel: Make UserOrKernelBuffer return KResult from read/write/memset
This allows us to simplify a whole bunch of call sites with TRY(). :^)
This commit is contained in:
parent
7bf8844499
commit
b481132418
29 changed files with 85 additions and 118 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue