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 A623AFA374F for ; Sat, 3 Jan 2026 10:15:06 +0000 (UTC) Received: from kara.freedesktop.org (unknown [131.252.210.166]) by gabe.freedesktop.org (Postfix) with ESMTPS id B11EE10E33A; Sat, 3 Jan 2026 10:15:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="q8SBg0g4"; dkim-atps=neutral Received: from kara.freedesktop.org (localhost [127.0.0.1]) by kara.freedesktop.org (Postfix) with ESMTP id 72D8044C86; Sat, 3 Jan 2026 10:06:57 +0000 (UTC) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=lists.freedesktop.org; s=20240201; t=1767434817; b=ILseiT2Tg8AyokLPbByUzNuvgSJO0S5cnuV9P+qoffas4AT3zJyvHpPNn301fNL0xC++Q fOA40AuUdHQXXR7N23vnm3+Lcv3jVUl1EUB806ffvdTAcxZUvfca3E5vt2LDQHztIw7zUKb 1zBlV9uH1id6Skf6ZbqgN2ZcF2BY5XUYKSOmx1IoYm9gkteZDpsh6AUxRlFJFWJKVipJypt lIxdu8sr3JfEd9OF6yAZ9t0Mtmlu02lJAyk/6vGf5SMLn8LjfveUlXhj0KXZG+Jo7lQvZGp yKTPoRAv8VAbq5uimi9zHyvrzqcMyoxwKO5B/GZYNiNu6iCT5zcoIMU9+UkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.freedesktop.org; s=20240201; t=1767434817; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=WWJU8ERnzbQGjBij7dNj1wpHu+RXf7J4RlihnDr1vyc=; b=s/Y3LIKDu0yT6heJ5y7ueSBcneGd8baXcD3S2B80wME6zxgLW/CYMMdDre2NGPvCTv9Nv qWclMJUKq3N7Ux4zL3wwXNsquJ+NgHb9VijnYlc7NMp9wWlwXXy9TQ5PMC+9iS20h4YjgeM ZEJJ9S1jHD8Zf2mbg7E+0fVjWUuhUA7perHuXQRId8AmuqQQB39ETzfDluxKukIV4ufhnvf tnArd8zwLYLIhtEF5pwAeuOncMMYbSaLo4bUrKA6x4GhsKDBMpENXbPb0PbWBVYGIx22gAF K3vynLJLP2i6yMyjwqEm+Wu9zCrFNz7qtvjoqj4RAnFnLoIebOo2bK/AVMiQ== ARC-Authentication-Results: i=1; mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Authentication-Results: mail.freedesktop.org; dkim=pass header.d=kernel.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=kernel.org policy.dmarc=quarantine Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by kara.freedesktop.org (Postfix) with ESMTPS id 2A2A944141 for ; Sat, 3 Jan 2026 10:06:55 +0000 (UTC) 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 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> Message-ID-Hash: PJTREI4LNKPM4YYGYDVYJ2MQ2SYMKOXB X-Message-ID-Hash: PJTREI4LNKPM4YYGYDVYJ2MQ2SYMKOXB X-MailFrom: dakr@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexandre Courbot , Alice Ryhl , Simona Vetter , Alistair Popple , Joel Fernandes , Eliot Courtney , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Nouveau development list Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30F76126F0A; Sat, 3 Jan 2026 10:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767435301; cv=none; b=PS2ogMSYBeUHXbMFSkxTu4Zw2B59Yijfw2KeVFiqRfbNEa5iuCu7re01O9aIuLguEjOMfsDtHeFSHE0G+bd9i4cwf4wSeATBRfVn3kCK+T3LEhExLlVLYTFtfhJacfCTPpbsXjqXqWh9Ulf+rKwQz1NnM4dw12L+TF9OjTHwgoo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767435301; c=relaxed/simple; bh=VJPG6cAxntp719Jx+yOECXPqz1CSvBhPq9ajb2tyTX4=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=qwydk5VFiRxyvsZNtKRg623hbdlzG7PzkU274+833W9RlfcwmbuYmLwQMf7PSHzjjaWjFq2co5g45ucbXDvh0g04CKK24Zz0AL7f4dlV2I3IAYCbG74QEYDAsy+adpKhQSO/vzFWATH+0vnnwamV/vBs0/M3mKKW9ioQA9jziaw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q8SBg0g4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q8SBg0g4" 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== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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> 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.