From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 543A6FC6179 for ; Sat, 3 Jan 2026 10:15:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8595410E125; Sat, 3 Jan 2026 10:15:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="q8SBg0g4"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 32A4110E125; Sat, 3 Jan 2026 10:15:01 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id D092A40D83; Sat, 3 Jan 2026 10:15:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D351AC113D0; Sat, 3 Jan 2026 10:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767435300; bh=VJPG6cAxntp719Jx+yOECXPqz1CSvBhPq9ajb2tyTX4=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=q8SBg0g495DLKSAVqjx4MtrtLI/KWiCvW4GWkdFlpUw+/KIF7qSVpRVDR62wiZOJp BlTgbdL/SAc88Bjz+53B3bzv9S+iRBg4Z/K14olgFfTnZ/fV2UWGTQDd7i92+CK9fQ t4lJxSoqZ1ue0A0dey4+5+O0sc78U4lJ9xNYqE7XoFUkeFknWE2i/MpGoozjoAQU1V akGoUm+0QeSU2kDSfmyILZx2Vgmmhb3e0AdFzs3hUUAnGxzdbmxhbcPYsL/5SyJUny g5mW3D9LQzzyWchTzZ2ccldRVzF5yac7YIzjhioffJ2YaAiRu+GVTA6Z2ryXr0cXTY k7LfN5J1ztzAQ== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 03 Jan 2026 11:14:55 +0100 Message-Id: Subject: Re: [PATCH v2 09/10] gpu: nova-core: simplify str_from_null_terminated Cc: "Alexandre Courbot" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" , "Alistair Popple" , "Joel Fernandes" , "Timur Tabi" , "Edwin Peer" , "Eliot Courtney" , , , , , "Lyude Paul" To: "John Hubbard" From: "Danilo Krummrich" References: <20251216-nova-misc-v2-0-dc7b42586c04@nvidia.com> <20251216-nova-misc-v2-9-dc7b42586c04@nvidia.com> <9c153278-c334-4649-8f73-ec5676ad25b0@nvidia.com> In-Reply-To: <9c153278-c334-4649-8f73-ec5676ad25b0@nvidia.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Sat Jan 3, 2026 at 4:37 AM CET, John Hubbard wrote: > On 12/15/25 8:27 PM, Alexandre Courbot wrote: >> The core library's `CStr` has a `from_bytes_until_nul` method that we >> can leverage to simplify this function. >>=20 >> Reviewed-by: Lyude Paul >> Signed-off-by: Alexandre Courbot >> --- >> drivers/gpu/nova-core/util.rs | 9 ++------- >> 1 file changed, 2 insertions(+), 7 deletions(-) >>=20 >> 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 @@ >> =20 >> /// 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; >> =20 >> - bytes >> - .iter() >> - .position(|&b| b =3D=3D 0) >> - .and_then(|null_pos| CStr::from_bytes_with_nul(&bytes[..=3Dnull= _pos]).ok()) >> + CStr::from_bytes_until_nul(bytes) >> + .ok() > > I guess I should have reviewed this patch, before creating my version of = this. > I went so far as to delete this file entirely, see if you prefer that, it= 's > otherwise the same core idea, but with more cleanup. [1] > > [1] https://lore.kernel.org/20260103013438.247759-1-jhubbard@nvidia.com Yes, let's remove str_from_null_terminated() entirely. >> .and_then(|cstr| cstr.to_str().ok()) Additionally, why do we return an Option here? While an error can only ever= happen if the given slice does not contain any NULL byte, I don't see why we discard = the error code.