[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4b589c75-c6d1-4733-80b1-a9a454445fb9@nvidia.com>
Date: Sat, 3 Jan 2026 16:21:52 -0500
From: Joel Fernandes <joelagnelf@...dia.com>
To: John Hubbard <jhubbard@...dia.com>, Danilo Krummrich <dakr@...nel.org>
Cc: Alexandre Courbot <acourbot@...dia.com>, Timur Tabi <ttabi@...dia.com>,
Alistair Popple <apopple@...dia.com>, Edwin Peer <epeer@...dia.com>,
Zhi Wang <zhiw@...dia.com>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, Bjorn Helgaas <bhelgaas@...gle.com>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
nouveau@...ts.freedesktop.org, rust-for-linux@...r.kernel.org,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] gpu: nova-core: use CStr::from_bytes_until_nul() and
remove util.rs
On 1/2/2026 8:34 PM, John Hubbard wrote:
> The util.rs module contained a single helper function,
> str_from_null_terminated(), which duplicated functionality that is now
> available in core::ffi::CStr.
>
> Specifically, CStr::from_bytes_until_nul() is available in the kernel's
> minimum supported Rust version (1.78.0), so it time to stop using this
> custom workaround.
>
> Signed-off-by: John Hubbard <jhubbard@...dia.com>
Reviewed-by: Joel Fernandes <joelagnelf@...dia.com>
Probably elf64_section() should also use CStr::from_bytes_until_nul() in gsp.rs?
Right now it does:
elf.get(name_idx..)
.and_then(|nstr| nstr.get(0..=nstr.iter().position(|b| *b == 0)?))
.and_then(|nstr| CStr::from_bytes_with_nul(nstr).ok())
thanks,
- Joel
> ---
> drivers/gpu/nova-core/gsp/commands.rs | 5 +++--
> drivers/gpu/nova-core/nova_core.rs | 1 -
> drivers/gpu/nova-core/util.rs | 16 ----------------
> 3 files changed, 3 insertions(+), 19 deletions(-)
> delete mode 100644 drivers/gpu/nova-core/util.rs
>
> diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
> index 0425c65b5d6f..a11fe6018091 100644
> --- a/drivers/gpu/nova-core/gsp/commands.rs
> +++ b/drivers/gpu/nova-core/gsp/commands.rs
> @@ -30,7 +30,6 @@
> },
> },
> sbuffer::SBufferIter,
> - util,
> };
>
> /// The `GspSetSystemInfo` command.
> @@ -209,7 +208,9 @@ impl GetGspStaticInfoReply {
> /// Returns the name of the GPU as a string, or `None` if the string given by the GSP was
> /// invalid.
> pub(crate) fn gpu_name(&self) -> Option<&str> {
> - util::str_from_null_terminated(&self.gpu_name)
> + CStr::from_bytes_until_nul(&self.gpu_name)
> + .ok()
> + .and_then(|cstr| cstr.to_str().ok())
> }
> }
>
> diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
> index b98a1c03f13d..c1121e7c64c5 100644
> --- a/drivers/gpu/nova-core/nova_core.rs
> +++ b/drivers/gpu/nova-core/nova_core.rs
> @@ -16,7 +16,6 @@
> mod num;
> mod regs;
> mod sbuffer;
> -mod util;
> mod vbios;
>
> pub(crate) const MODULE_NAME: &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
> diff --git a/drivers/gpu/nova-core/util.rs b/drivers/gpu/nova-core/util.rs
> deleted file mode 100644
> index 4b503249a3ef..000000000000
> --- a/drivers/gpu/nova-core/util.rs
> +++ /dev/null
> @@ -1,16 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -
> -/// Converts a null-terminated byte slice to a string, or `None` if the array does not
> -/// contains any null byte or contains invalid characters.
> -///
> -/// Contrary to [`kernel::str::CStr::from_bytes_with_nul`], the null byte can be anywhere in the
> -/// slice, and not only in the last position.
> -pub(crate) fn str_from_null_terminated(bytes: &[u8]) -> Option<&str> {
> - use kernel::str::CStr;
> -
> - bytes
> - .iter()
> - .position(|&b| b == 0)
> - .and_then(|null_pos| CStr::from_bytes_with_nul(&bytes[..=null_pos]).ok())
> - .and_then(|cstr| cstr.to_str().ok())
> -}
>
> base-commit: 7acc70476f14661149774ab88d3fe23d83ba4249
Powered by blists - more mailing lists