[PATCH 5/7] drm/nova: use `zerocopy` in bootloader.rs
Pedro Yudi Honda
niyudi.honda em usp.br
Seg Jun 22 15:40:25 -03 2026
From: Pedro Yudi Honda <niyudi.honda em usp.br>
In firmware/fwsec/bootloader.rs, replace the following `transmute`
traits with their `zerocopy` equivalents:
- `transmute::FromBytes` -> `zerocopy::FromBytes`
- `transmute::AsBytes` -> `zerocopy::IntoBytes`
- add `zerocopy::Immutable` where necessary
Update call sites accordingly.
Signed-off-by: Pedro Yudi Honda <niyudi.honda em usp.br>
---
.../gpu/nova-core/firmware/fwsec/bootloader.rs | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
index 5d2ac63b95e8..3d7eb617ba90 100644
--- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
@@ -23,14 +23,8 @@
Alignment, //
},
sizes,
- transmute::{
- AsBytes,
- FromBytes, //
- },
};
-use zerocopy::FromBytes as _;
-
use crate::{
driver::Bar0,
falcon::{
@@ -61,7 +55,7 @@
///
/// Most of its fields appear to be legacy and carry incorrect values, so they are left unused.
#[repr(C)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, FromBytes)]
struct BootloaderDesc {
/// Starting tag of bootloader.
start_tag: u32,
@@ -77,15 +71,13 @@ struct BootloaderDesc {
/// Size of data section in the image. Unused as we build the data section ourselves.
_data_size: u32,
}
-// SAFETY: any byte sequence is valid for this struct.
-unsafe impl FromBytes for BootloaderDesc {}
/// Structure used by the boot-loader to load the rest of the code.
///
/// This has to be filled by the GPU driver and copied into DMEM at offset
/// [`BootloaderDesc.dmem_load_off`].
#[repr(C, packed)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, IntoBytes, zerocopy_derive::Immutable)]
struct BootloaderDmemDescV2 {
/// Reserved, should always be first element.
reserved: [u32; 4],
@@ -124,8 +116,6 @@ struct BootloaderDmemDescV2 {
/// Arguments to be passed to the target firmware being loaded.
argv: u32,
}
-// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
-unsafe impl AsBytes for BootloaderDmemDescV2 {}
/// Wrapper for [`FwsecFirmware`] that includes the bootloader performing the actual load
/// operation.
@@ -164,7 +154,7 @@ pub(crate) fn new(
fw.data()
.get(desc_offset..)
- .and_then(BootloaderDesc::from_bytes_copy_prefix)
+ .and_then(|b| BootloaderDesc::read_from_prefix(b).ok())
.ok_or(EINVAL)?
.0
};
--
2.34.1
Mais detalhes sobre a lista de discussão kernel