[PATCH v2 2/7] gpu: nova-core: vbios: remove unneeded u8 conversions

Alexandre Courbot posted 7 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v2 2/7] gpu: nova-core: vbios: remove unneeded u8 conversions
Posted by Alexandre Courbot 3 months, 1 week ago
These variables were read from the u8 array `data` and converted to a
`usize`, before being converted back to a `u8`. Just re-read them from
the source to avoid using `as`.

Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/vbios.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index 943b0dac31df..dbe0d6e4a015 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -911,9 +911,9 @@ fn new(dev: &device::Device, data: &[u8]) -> Result<Self> {
 
         Ok(PmuLookupTable {
             version: data[0],
-            header_len: header_len as u8,
-            entry_len: entry_len as u8,
-            entry_count: entry_count as u8,
+            header_len: data[1],
+            entry_len: data[2],
+            entry_count: data[3],
             table_data,
         })
     }

-- 
2.51.0
Re: [PATCH v2 2/7] gpu: nova-core: vbios: remove unneeded u8 conversions
Posted by Joel Fernandes 3 months, 1 week ago
Hello Alex,

On 10/27/2025 8:54 AM, Alexandre Courbot wrote:
> These variables were read from the u8 array `data` and converted to a
> `usize`, before being converted back to a `u8`. Just re-read them from
> the source to avoid using `as`.
> 
> Acked-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/gpu/nova-core/vbios.rs | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
> index 943b0dac31df..dbe0d6e4a015 100644
> --- a/drivers/gpu/nova-core/vbios.rs
> +++ b/drivers/gpu/nova-core/vbios.rs
> @@ -911,9 +911,9 @@ fn new(dev: &device::Device, data: &[u8]) -> Result<Self> {
>  
>          Ok(PmuLookupTable {
>              version: data[0],
> -            header_len: header_len as u8,
> -            entry_len: entry_len as u8,
> -            entry_count: entry_count as u8,
> +            header_len: data[1],
> +            entry_len: data[2],
> +            entry_count: data[3],
>              table_data,

Why not just change PmuLookupTable to:

struct PmuLookupTable {
    version: u8,
    header_len: usize,
    entry_len: usize,
    entry_count: usize,
    table_data: KVec<u8>,
}

That is cleaner and removes the issue while allowing to use the local variables
(and also makes sense to be usize as these 3 fields are size-like fields).

thanks,

 - Joel
Re: [PATCH v2 2/7] gpu: nova-core: vbios: remove unneeded u8 conversions
Posted by Alexandre Courbot 3 months, 1 week ago
On Tue Oct 28, 2025 at 2:41 AM JST, Joel Fernandes wrote:
> Hello Alex,
>
> On 10/27/2025 8:54 AM, Alexandre Courbot wrote:
>> These variables were read from the u8 array `data` and converted to a
>> `usize`, before being converted back to a `u8`. Just re-read them from
>> the source to avoid using `as`.
>> 
>> Acked-by: Danilo Krummrich <dakr@kernel.org>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>>  drivers/gpu/nova-core/vbios.rs | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
>> index 943b0dac31df..dbe0d6e4a015 100644
>> --- a/drivers/gpu/nova-core/vbios.rs
>> +++ b/drivers/gpu/nova-core/vbios.rs
>> @@ -911,9 +911,9 @@ fn new(dev: &device::Device, data: &[u8]) -> Result<Self> {
>>  
>>          Ok(PmuLookupTable {
>>              version: data[0],
>> -            header_len: header_len as u8,
>> -            entry_len: entry_len as u8,
>> -            entry_count: entry_count as u8,
>> +            header_len: data[1],
>> +            entry_len: data[2],
>> +            entry_count: data[3],
>>              table_data,
>
> Why not just change PmuLookupTable to:
>
> struct PmuLookupTable {
>     version: u8,
>     header_len: usize,
>     entry_len: usize,
>     entry_count: usize,
>     table_data: KVec<u8>,
> }
>
> That is cleaner and removes the issue while allowing to use the local variables
> (and also makes sense to be usize as these 3 fields are size-like fields).

That would work! But while trying I also figured we could just split the
header into its own `repr(C)` struct and use `FromBytes` on it, which
would achieve the same result with less array indexing.

Actually, we could do that for a bunch of structures in this file, so I
think I'll just try and do it that way.