Kernel: Fix reading expansion ROM SysFS node

Previously, reads would only be successful for offset 0. For this
reason, the maximum size that could be correctly read from the PCI
expansion ROM SysFS node was limited to the block size, and
subsequent blocks would fail. This commit fixes the computation of
the number of bytes to read.
This commit is contained in:
Robin Voetter 2023-06-18 01:48:26 +02:00 committed by Jelle Raaijmakers
parent c90136d48d
commit a433cbefbe
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00

View file

@ -39,12 +39,9 @@ ErrorOr<size_t> PCIDeviceExpansionROMSysFSComponent::read_bytes(off_t offset, si
if (unsigned_offset >= m_option_rom_size) if (unsigned_offset >= m_option_rom_size)
return 0; return 0;
auto blob = TRY(try_to_generate_buffer(unsigned_offset, count)); ssize_t nread = min(static_cast<off_t>(m_option_rom_size - offset), static_cast<off_t>(count));
if (static_cast<size_t>(offset) >= blob->size()) auto blob = TRY(try_to_generate_buffer(unsigned_offset, nread));
return 0; TRY(buffer.write(blob->bytes()));
ssize_t nread = min(static_cast<off_t>(blob->size() - offset), static_cast<off_t>(count));
TRY(buffer.write(blob->data() + offset, nread));
return nread; return nread;
} }