Re: [PATCH v2 4/5] drm/nova: use `zerocopy` in bootloader.rs

Alistair Popple <[email protected]>
Newsgroups dev.linux.lists.nova-gpu,org.freedesktop.lists.dri-devel,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On 2026-07-02 at 22:03 +1000, Pedro Yudi Honda <[email protected]> wrote...
> 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.

Reviewed-by: Alistair Popple <[email protected]>

> 
> Signed-off-by: Pedro Yudi Honda <[email protected]>
> ---
>  .../gpu/nova-core/firmware/fwsec/bootloader.rs | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> index 66b9f4d1b41c..03d3090bd9ef 100644
> --- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> +++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> @@ -18,15 +18,9 @@
>          Alignable,
>          Alignment, //
>      },
> -    sizes,
> -    transmute::{
> -        AsBytes,
> -        FromBytes, //
> -    },
> +    sizes, //
>  };
>  
> -use zerocopy::FromBytes as _;
> -
>  use crate::{
>      driver::Bar0,
>      falcon::{
> @@ -57,7 +51,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,
> @@ -73,15 +67,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],
> @@ -120,8 +112,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.
> @@ -160,7 +150,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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.