From a433cbefbe30db3055f4153e75097e8ef1ce48d4 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sun, 18 Jun 2023 01:48:26 +0200 Subject: [PATCH] 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. --- .../SysFS/Subsystems/Bus/PCI/DeviceExpansionROM.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceExpansionROM.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceExpansionROM.cpp index 12a40d7fe0b..ebc7b846d31 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceExpansionROM.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceExpansionROM.cpp @@ -39,12 +39,9 @@ ErrorOr 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(offset) >= blob->size()) - return 0; - - ssize_t nread = min(static_cast(blob->size() - offset), static_cast(count)); - TRY(buffer.write(blob->data() + offset, nread)); + ssize_t nread = min(static_cast(m_option_rom_size - offset), static_cast(count)); + auto blob = TRY(try_to_generate_buffer(unsigned_offset, nread)); + TRY(buffer.write(blob->bytes())); return nread; }