From: Pedro Yudi Honda <[email protected]> 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 <[email protected]> --- .../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 13af1c381df1..6f1c8daad7d3 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
