[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250718073633.194032-1-krakow20@gmail.com>
Date: Fri, 18 Jul 2025 00:36:23 -0700
From: Rhys Lloyd <krakow20@...il.com>
To: acourbot@...dia.com,
dakr@...nel.org
Cc: Rhys Lloyd <krakow20@...il.com>,
rust-for-linux@...r.kernel.org,
airlied@...il.com,
simona@...ll.ch,
nouveau@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] gpu: nova-core: vbios: use offset_of in PmuLookupTableHeader::new
Use the offset_of macro for each struct field, annotate the
`PmuLookupTableHeader` struct with `#[repr(C)]` attribute,
and add a TODO message to use FromBytes when available.
Signed-off-by: Rhys Lloyd <krakow20@...il.com>
---
drivers/gpu/nova-core/vbios.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index a77d7a4c8595..cedfcf3476bb 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -893,6 +893,7 @@ fn try_from(base: BiosImageBase) -> Result<Self> {
///
/// See the [`PmuLookupTable`] description for more information.
#[expect(dead_code)]
+#[repr(C)]
struct PmuLookupTableHeader {
version: u8,
header_len: u8,
@@ -901,16 +902,17 @@ struct PmuLookupTableHeader {
}
impl PmuLookupTableHeader {
+ // TODO[TRSM]: use FromBytes::from_bytes when it becomes available.
fn new(data: &[u8]) -> Result<Self> {
if data.len() < core::mem::size_of::<Self>() {
return Err(EINVAL);
}
Ok(PmuLookupTableHeader {
- version: data[0],
- header_len: data[1],
- entry_len: data[2],
- entry_count: data[3],
+ version: data[const { core::mem::offset_of!(PmuLookupTableHeader, version) }],
+ header_len: data[const { core::mem::offset_of!(PmuLookupTableHeader, header_len) }],
+ entry_len: data[const { core::mem::offset_of!(PmuLookupTableHeader, entry_len) }],
+ entry_count: data[const { core::mem::offset_of!(PmuLookupTableHeader, entry_count) }],
})
}
}
base-commit: 14ae91a81ec8fa0bc23170d4aa16dd2a20d54105
prerequisite-patch-id: 6f9311de987d56f4313d5fbdd85ed8c48a44e78c
--
2.50.1
Powered by blists - more mailing lists