Re: [PATCH v4 12/20] gpu: nova-core: vbios: read PMU lookup entries using FromBytes
From: John Hubbard
Date: Fri May 22 2026 - 22:55:13 EST
On 5/18/26 7:55 PM, Eliot Courtney wrote:
> This simplifies the construction of `PmuLookupTableEntry` and is
> allowed now that the driver can assume it is little endian.
>
> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
> ---
> drivers/gpu/nova-core/vbios.rs | 23 +++++++++--------------
> 1 file changed, 9 insertions(+), 14 deletions(-)
Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx>
thanks,
--
John Hubbard
>
> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
> index 470e0e2a81ab..987eb1948314 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<Self> {
> - if data.len() < core::mem::size_of::<Self>() {
> - 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 @@ fn lookup_index(&self, idx: u8) -> Result<PmuLookupTableEntry> {
> }
>
> 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
>