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 <[email protected]>
> ---
>  drivers/gpu/nova-core/vbios.rs | 23 +++++++++--------------
>  1 file changed, 9 insertions(+), 14 deletions(-)

Reviewed-by: John Hubbard <[email protected]>

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
> 

Reply via email to