1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 10:20:45 +00:00

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

View File

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