From: Miguel Ojeda <ojeda@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org,
"Joshua Liebow-Feeser" <joshlf@google.com>,
"Jack Wrenn" <jswrenn@google.com>,
"Alexandre Courbot" <acourbot@nvidia.com>
Subject: [PATCH v2 19/19] gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy`
Date: Mon, 8 Jun 2026 16:14:38 +0200 [thread overview]
Message-ID: <20260608141439.182634-20-ojeda@kernel.org> (raw)
In-Reply-To: <20260608141439.182634-1-ojeda@kernel.org>
Now that we have `zerocopy` support, we can avoid some `unsafe` code.
For instance, for `FalconUCodeDescV2`, we can replace the `unsafe impl
FromBytes` by safely deriving `zerocopy`'s `FromBytes` and then calling
`read_from_prefix`.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
drivers/gpu/nova-core/firmware.rs | 5 +----
drivers/gpu/nova-core/vbios.rs | 6 ++++--
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
index 6c2ab69cb605..ad37994ac15a 100644
--- a/drivers/gpu/nova-core/firmware.rs
+++ b/drivers/gpu/nova-core/firmware.rs
@@ -48,7 +48,7 @@ fn request_firmware(
/// Structure used to describe some firmwares, notably FWSEC-FRTS.
#[repr(C)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, FromBytes)]
pub(crate) struct FalconUCodeDescV2 {
/// Header defined by 'NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*' in OpenRM.
hdr: u32,
@@ -84,9 +84,6 @@ pub(crate) struct FalconUCodeDescV2 {
pub(crate) alt_dmem_load_size: u32,
}
-// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
-unsafe impl FromBytes for FalconUCodeDescV2 {}
-
/// Structure used to describe some firmwares, notably FWSEC-FRTS.
#[repr(C)]
#[derive(Debug, Clone)]
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index ebda28e596c5..8b7d17a24660 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -16,6 +16,8 @@
transmute::FromBytes,
};
+use zerocopy::FromBytes as _;
+
use crate::{
driver::Bar0,
firmware::{
@@ -1011,8 +1013,8 @@ pub(crate) fn header(&self) -> Result<FalconUCodeDesc> {
let data = self.base.data.get(falcon_ucode_offset..).ok_or(EINVAL)?;
match ver {
2 => {
- let v2 = FalconUCodeDescV2::from_bytes_copy_prefix(data)
- .ok_or(EINVAL)?
+ let v2 = FalconUCodeDescV2::read_from_prefix(data)
+ .map_err(|_| EINVAL)?
.0;
Ok(FalconUCodeDesc::V2(v2))
}
--
2.54.0
next prev parent reply other threads:[~2026-06-08 14:16 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 14:14 [PATCH v2 00/19] `zerocopy` support Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 01/19] scripts: generate_rust_analyzer: support passing env vars Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 02/19] rust: kbuild: show the right `quiet_cmd_rustc_procmacrolibrary` Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 03/19] rust: kbuild: remove unused variable Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 04/19] rust: kbuild: define `procmacro-name` function Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 05/19] rust: kbuild: define `procmacro-extension` variable Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 06/19] rust: kbuild: support per-target environment variables Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 07/19] rust: kbuild: support `skip_clippy` for `rustc_procmacro` Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 08/19] rust: zerocopy: import crate Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 09/19] rust: zerocopy: add SPDX License Identifiers Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 10/19] rust: zerocopy: remove float `Display` support Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 11/19] rust: zerocopy: add `README.md` Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 12/19] rust: zerocopy: enable support in kbuild Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 13/19] rust: zerocopy-derive: import crate Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 14/19] rust: zerocopy-derive: add SPDX License Identifiers Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 15/19] rust: zerocopy-derive: avoid generating non-ASCII identifiers Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 16/19] rust: zerocopy-derive: add `README.md` Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 17/19] rust: zerocopy-derive: enable support in kbuild Miguel Ojeda
2026-06-08 14:14 ` [PATCH v2 18/19] rust: prelude: add `zerocopy{,_derive}::FromBytes` Miguel Ojeda
2026-06-08 14:14 ` Miguel Ojeda [this message]
2026-06-08 14:32 ` [PATCH v2 19/19] gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy` Gary Guo
2026-06-08 14:36 ` Danilo Krummrich
2026-06-08 15:30 ` Miguel Ojeda
2026-06-09 10:45 ` [PATCH v2 00/19] `zerocopy` support Miguel Ojeda
2026-06-09 12:21 ` Alice Ryhl
2026-06-09 12:32 ` Gary Guo
2026-06-09 12:43 ` Alice Ryhl
2026-06-09 13:08 ` 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=20260608141439.182634-20-ojeda@kernel.org \
--to=ojeda@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=joshlf@google.com \
--cc=jswrenn@google.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.