[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <678b25aba2bdb2e08818780f6ae16470e83fb8ff.camel@redhat.com>
Date: Thu, 11 Dec 2025 17:10:16 -0500
From: lyude@...hat.com
To: Alexandre Courbot <acourbot@...dia.com>, Danilo Krummrich
<dakr@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, David Airlie
<airlied@...il.com>, Simona Vetter <simona@...ll.ch>
Cc: John Hubbard <jhubbard@...dia.com>, Alistair Popple
<apopple@...dia.com>, Joel Fernandes <joelagnelf@...dia.com>, Timur Tabi
<ttabi@...dia.com>, Edwin Peer <epeer@...dia.com>,
nouveau@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH 9/9] gpu: nova-core: simplify str_from_null_terminated
Reviewed-by: Lyude Paul <lyude@...hat.com>
On Mon, 2025-12-08 at 18:27 +0900, Alexandre Courbot wrote:
> The core library's `CStr` has a `from_bytes_until_nul` method that we
> can leverage to simplify this function.
>
> Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
> ---
> drivers/gpu/nova-core/util.rs | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/util.rs b/drivers/gpu/nova-
> core/util.rs
> index 8b2a4b99c55b..2cccbce78c14 100644
> --- a/drivers/gpu/nova-core/util.rs
> +++ b/drivers/gpu/nova-core/util.rs
> @@ -2,15 +2,10 @@
>
> /// 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 [`core::ffi::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 core::ffi::CStr;
>
> - bytes
> - .iter()
> - .position(|&b| b == 0)
> - .and_then(|null_pos|
> CStr::from_bytes_with_nul(&bytes[..=null_pos]).ok())
> + CStr::from_bytes_until_nul(bytes)
> + .ok()
> .and_then(|cstr| cstr.to_str().ok())
> }
Powered by blists - more mailing lists