From: Alistair Popple <apopple@nvidia.com>
To: Pedro Yudi Honda <niyudi.honda@usp.br>
Cc: dakr@kernel.org, acourbot@nvidia.com, nico.antinori.7@gmail.com,
aliceryhl@google.com, airlied@gmail.com, simona@ffwll.ch,
dri-devel@lists.freedesktop.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, nova-gpu@lists.linux.dev
Subject: Re: [PATCH v2 1/5] drm/nova: use `zerocopy` in firmware.rs
Date: Mon, 6 Jul 2026 17:15:51 +1000 [thread overview]
Message-ID: <aktV7gUmA8TDYL8l@nvdebian.thelocal> (raw)
In-Reply-To: <20260702120324.40388-2-niyudi.honda@gmail.com>
On 2026-07-02 at 22:03 +1000, Pedro Yudi Honda <niyudi.honda@usp.br> wrote...
> From: Pedro Yudi Honda <niyudi.honda@usp.br>
>
> In firmware.rs, replace the following `transmute` traits with their
> `zerocopy` equivalents:
>
> - `transmute::FromBytes` -> `zerocopy::FromBytes`
>
> Update call sites accordingly.
>
> Note that the module `elf` is untouched, as the bindings generated by
> bindgen do not implement `FromBytes` for the structs.
Also I believe this module is pretty temporary and going to go away.
Everything here is pretty mechanical though, and looks good to me so:
Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Pedro Yudi Honda <niyudi.honda@usp.br>
> ---
> drivers/gpu/nova-core/firmware.rs | 10 +++-------
> drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 4 +++-
> 2 files changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
> index a94820a3b335..80ce0df244a8 100644
> --- a/drivers/gpu/nova-core/firmware.rs
> +++ b/drivers/gpu/nova-core/firmware.rs
> @@ -11,8 +11,7 @@
> device,
> firmware,
> prelude::*,
> - str::CString,
> - transmute::FromBytes, //
> + str::CString, //
> };
>
> use crate::{
> @@ -347,7 +346,7 @@ fn no_patch_signature(self) -> FirmwareObject<F, Signed> {
>
> /// Header common to most firmware files.
> #[repr(C)]
> -#[derive(Debug, Clone)]
> +#[derive(Debug, Clone, FromBytes)]
> struct BinHdr {
> /// Magic number, must be `0x10de`.
> bin_magic: u32,
> @@ -363,9 +362,6 @@ struct BinHdr {
> data_size: u32,
> }
>
> -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
> -unsafe impl FromBytes for BinHdr {}
> -
> // A firmware blob starting with a `BinHdr`.
> struct BinFirmware<'a> {
> hdr: BinHdr,
> @@ -381,7 +377,7 @@ fn new(fw: &'a firmware::Firmware) -> Result<Self> {
>
> fw.get(0..size_of::<BinHdr>())
> // Extract header.
> - .and_then(BinHdr::from_bytes_copy)
> + .and_then(|b| BinHdr::read_from_bytes(b).ok())
> // Validate header.
> .filter(|hdr| hdr.bin_magic == BIN_MAGIC)
> .map(|hdr| Self { hdr, fw })
> diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> index d9fafd2eea5b..66b9f4d1b41c 100644
> --- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> +++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
> @@ -25,6 +25,8 @@
> },
> };
>
> +use zerocopy::FromBytes as _;
> +
> use crate::{
> driver::Bar0,
> falcon::{
> @@ -150,7 +152,7 @@ pub(crate) fn new(
> let hdr = fw
> .data()
> .get(0..size_of::<BinHdr>())
> - .and_then(BinHdr::from_bytes_copy)
> + .and_then(|b| BinHdr::read_from_bytes(b).ok())
> .ok_or(EINVAL)?;
>
> let desc = {
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-07-06 7:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 12:03 [RESEND PATCH v2 0/5] drm/nova: replace `transmute` with `zerocopy` Pedro Yudi Honda
2026-07-02 12:03 ` [PATCH v2 1/5] drm/nova: use `zerocopy` in firmware.rs Pedro Yudi Honda
2026-07-06 7:15 ` Alistair Popple [this message]
2026-07-02 12:03 ` [PATCH v2 2/5] drm/nova: use `zerocopy` in booter.rs Pedro Yudi Honda
2026-07-06 11:39 ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 3/5] drm/nova: use `zerocopy` in fwsec.rs Pedro Yudi Honda
2026-07-06 11:43 ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 4/5] drm/nova: use `zerocopy` in bootloader.rs Pedro Yudi Honda
2026-07-06 11:44 ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 5/5] drm/nova: use `zerocopy` in riscv.rs Pedro Yudi Honda
2026-07-06 11:44 ` Alistair Popple
2026-07-04 13:00 ` [RESEND PATCH v2 0/5] drm/nova: replace `transmute` with `zerocopy` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aktV7gUmA8TDYL8l@nvdebian.thelocal \
--to=apopple@nvidia.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=nico.antinori.7@gmail.com \
--cc=niyudi.honda@usp.br \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox