[PATCH v2] gpu: nova-core: vbios: use size_of instead of magic number

Rhys Lloyd posted 1 patch 2 months, 2 weeks ago
drivers/gpu/nova-core/vbios.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH v2] gpu: nova-core: vbios: use size_of instead of magic number
Posted by Rhys Lloyd 2 months, 2 weeks ago
12 is identical to the value of `size_of::<BitHeader>()`,
so use the latter instead.

Signed-off-by: Rhys Lloyd <krakow20@gmail.com>
---
Changes in v2:
- Added `#[repr(C)]` to `BitHeader`

---
 drivers/gpu/nova-core/vbios.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index 5b5d9f38cbb3..912698308102 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -346,6 +346,7 @@ fn image_size_bytes(&self) -> usize {
 /// [`FwSecBiosImage`].
 #[derive(Debug, Clone, Copy)]
 #[expect(dead_code)]
+#[repr(C)]
 struct BitHeader {
     /// 0h: BIT Header Identifier (BMP=0x7FFF/BIT=0xB8FF)
     id: u16,
@@ -365,7 +366,7 @@ struct BitHeader {

 impl BitHeader {
     fn new(data: &[u8]) -> Result<Self> {
-        if data.len() < 12 {
+        if data.len() < core::mem::size_of::<Self>() {
             return Err(EINVAL);
         }


base-commit: 14ae91a81ec8fa0bc23170d4aa16dd2a20d54105
--
2.50.1
Re: [PATCH v2] gpu: nova-core: vbios: use size_of instead of magic number
Posted by Alexandre Courbot 2 months, 1 week ago
On Fri Jul 18, 2025 at 4:36 PM JST, Rhys Lloyd wrote:
> 12 is identical to the value of `size_of::<BitHeader>()`,
> so use the latter instead.
>
> Signed-off-by: Rhys Lloyd <krakow20@gmail.com>

Looking good - I'll push this to nova-next unless someone complains.
Thanks!