[PATCH v2 4/5] gpu: nova-core: use checked arithmetic in BinFirmware::data
Joel Fernandes
joelagnelf at nvidia.com
Mon Jan 26 12:23:04 PST 2026
Use checked_add() when computing the firmware data end offset in the
BinFirmware::data() method. The data_offset and data_size fields come
from the BinHdr structure parsed from the firmware file header.
Reviewed-by: Zhi Wang <zhiw at nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf at nvidia.com>
---
drivers/gpu/nova-core/firmware.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
index 68779540aa28..4f57a270e142 100644
--- a/drivers/gpu/nova-core/firmware.rs
+++ b/drivers/gpu/nova-core/firmware.rs
@@ -394,8 +394,9 @@ fn new(fw: &'a firmware::Firmware) -> Result<Self> {
fn data(&self) -> Option<&[u8]> {
let fw_start = usize::from_safe_cast(self.hdr.data_offset);
let fw_size = usize::from_safe_cast(self.hdr.data_size);
+ let fw_end = fw_start.checked_add(fw_size)?;
- self.fw.get(fw_start..fw_start + fw_size)
+ self.fw.get(fw_start..fw_end)
}
}
--
2.34.1
More information about the linux-riscv
mailing list