]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpu: nova-core: use checked arithmetic in BinFirmware::data
authorJoel Fernandes <joelagnelf@nvidia.com>
Mon, 26 Jan 2026 20:23:04 +0000 (15:23 -0500)
committerAlexandre Courbot <acourbot@nvidia.com>
Tue, 24 Feb 2026 23:16:55 +0000 (08:16 +0900)
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@nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260126202305.2526618-5-joelagnelf@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
drivers/gpu/nova-core/firmware.rs

index 68779540aa2842a8cd46ef97ab642091db7902de..4f57a270e1421fc0d32c484f14a1404e7f08c7ee 100644 (file)
@@ -394,8 +394,9 @@ impl<'a> BinFirmware<'a> {
     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)
     }
 }