mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: John Hubbard <jhubbard@nvidia.com>, Danilo Krummrich <dakr@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Edwin Peer" <epeer@nvidia.com>, "Zhi Wang" <zhiw@nvidia.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"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>,
	nouveau@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
Date: Sat, 3 Jan 2026 16:21:52 -0500	[thread overview]
Message-ID: <4b589c75-c6d1-4733-80b1-a9a454445fb9@nvidia.com> (raw)
In-Reply-To: <20260103013438.247759-1-jhubbard@nvidia.com>



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@nvidia.com>

Reviewed-by: Joel Fernandes <joelagnelf@nvidia.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


  reply	other threads:[~2026-01-03 21:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-03  1:34 John Hubbard
2026-01-03 21:21 ` Joel Fernandes [this message]
2026-01-06  2:29   ` John Hubbard
2026-01-06 12:02 ` Danilo Krummrich
2026-01-06 22:09   ` John Hubbard
2026-01-06 22:44     ` Danilo Krummrich
2026-01-07  0:24       ` John Hubbard
2026-01-07 10:20         ` Danilo Krummrich

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=4b589c75-c6d1-4733-80b1-a9a454445fb9@nvidia.com \
    --to=joelagnelf@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=epeer@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=zhiw@nvidia.com \
    /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

all inboxes | Powered by JetHome®