summaryrefslogtreecommitdiff
path: root/drivers/gpu/nova-core
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2025-10-29 00:07:39 +0900
committerAlexandre Courbot <acourbot@nvidia.com>2025-11-05 20:29:47 +0900
commit46768644a164f0f5eaa06fdf93718edcbbc47b64 (patch)
tree3e00f74b9dd7ae269e328b42586e9eec083bf9b1 /drivers/gpu/nova-core
parent56bb4b17a696a91aeaf7939d467a4f586edb01c6 (diff)
gpu: nova-core: vbios: use FromBytes for BitHeader
Use `from_bytes_copy_prefix` to create `BitHeader` instead of building it ourselves from the bytes stream. This lets us remove a few array accesses and results in shorter code. Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Message-ID: <20251029-nova-vbios-frombytes-v1-4-ac441ebc1de3@nvidia.com>
Diffstat (limited to 'drivers/gpu/nova-core')
-rw-r--r--drivers/gpu/nova-core/vbios.rs23
1 files changed, 6 insertions, 17 deletions
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index 81544b33077d..0efd2502c230 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -374,30 +374,19 @@ struct BitHeader {
checksum: u8,
}
+// SAFETY: all bit patterns are valid for `BitHeader`.
+unsafe impl FromBytes for BitHeader {}
+
impl BitHeader {
fn new(data: &[u8]) -> Result<Self> {
- if data.len() < core::mem::size_of::<Self>() {
- return Err(EINVAL);
- }
-
- let mut signature = [0u8; 4];
- signature.copy_from_slice(&data[2..6]);
+ let (header, _) = BitHeader::from_bytes_copy_prefix(data).ok_or(EINVAL)?;
// Check header ID and signature
- let id = u16::from_le_bytes([data[0], data[1]]);
- if id != 0xB8FF || &signature != b"BIT\0" {
+ if header.id != 0xB8FF || &header.signature != b"BIT\0" {
return Err(EINVAL);
}
- Ok(BitHeader {
- id,
- signature,
- bcd_version: u16::from_le_bytes([data[6], data[7]]),
- header_size: data[8],
- token_size: data[9],
- token_entries: data[10],
- checksum: data[11],
- })
+ Ok(header)
}
}