From: Eliot Courtney Date: Mon, 25 May 2026 13:57:30 +0000 (+0900) Subject: gpu: nova-core: vbios: read PMU lookup entries using FromBytes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c22095fddad76e1d5387292589b4d225bc1b2ba1;p=thirdparty%2Fkernel%2Flinux.git gpu: nova-core: vbios: read PMU lookup entries using FromBytes This simplifies the construction of `PmuLookupTableEntry` and is allowed now that the driver can assume it is little endian. Reviewed-by: John Hubbard Signed-off-by: Eliot Courtney Link: https://patch.msgid.link/20260525-fix-vbios-v5-12-e5e455251537@nvidia.com Signed-off-by: Danilo Krummrich --- diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs index 470e0e2a81abd..987eb1948314f 100644 --- a/drivers/gpu/nova-core/vbios.rs +++ b/drivers/gpu/nova-core/vbios.rs @@ -897,19 +897,8 @@ struct PmuLookupTableEntry { data: u32, } -impl PmuLookupTableEntry { - fn new(data: &[u8]) -> Result { - if data.len() < core::mem::size_of::() { - return Err(EINVAL); - } - - Ok(PmuLookupTableEntry { - application_id: data[0], - target_id: data[1], - data: u32::from_le_bytes(data[2..6].try_into().map_err(|_| EINVAL)?), - }) - } -} +// SAFETY: all bit patterns are valid for `PmuLookupTableEntry`. +unsafe impl FromBytes for PmuLookupTableEntry {} #[repr(C)] struct PmuLookupTableHeader { @@ -963,7 +952,13 @@ impl PmuLookupTable { } let index = (usize::from(idx)) * usize::from(self.header.entry_len); - PmuLookupTableEntry::new(&self.table_data[index..]) + let (entry, _) = self + .table_data + .get(index..) + .and_then(PmuLookupTableEntry::from_bytes_copy_prefix) + .ok_or(EINVAL)?; + + Ok(entry) } // find entry by type value