From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 AC19A2D24B6 for ; Thu, 11 Dec 2025 22:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765491025; cv=none; b=Kn2BSM1BRghTyxHJQEQYp4lTYtQXS5wY0ir4nkeDyZY83lVpCzRZKjn9YOTeIq1+vm75DtaSNun0esfRq4hPIU0JbElQhI12gc038+4w9vuHXy+41FNuVer965/0uqkljWXCnM8gYvyhSKO6gntq+kqhw84dF0iGe9poJAUH2Cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765491025; c=relaxed/simple; bh=DRrw2mEFcasOCUpxE3z89bZ0+erUgaOzx3WZhCZMjA4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=RwqLDjX6bXhqQfrwl9gU3qFf4JUN4wuwitbKf8/uVvOhUv/n8T8PGS9HquVOo3AhVDGqMf+qxUwB4E+uU3bM8Jz6VR2wOEm7JXL+g2DYcC33SGvO0bLUYmgmGISaUm2yM2x/FiO4PBKYUKJoaduJVL6htll8PL/4Wskcgv4HSVg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JjT2tMOh; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=WsxV7v0j; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JjT2tMOh"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="WsxV7v0j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765491022; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DRrw2mEFcasOCUpxE3z89bZ0+erUgaOzx3WZhCZMjA4=; b=JjT2tMOh2ZQPmVarteR+UC3/+gtpu5oYXnHsaXLBl3T2XJD9pjO89EfOKWYN3mt47t+jgO j/UtHR4qGdiXS6BV2UOEGEdJGBDllzOfH18cQO1iYHaNZgyDcjANaSzCcPOHTAPSQ8ygtH bWrCkQ9oAc8tOVucy3aUz4Mt2Heq3Ys= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-mTgAdLCzMdKHgGH5-KKyiw-1; Thu, 11 Dec 2025 17:10:21 -0500 X-MC-Unique: mTgAdLCzMdKHgGH5-KKyiw-1 X-Mimecast-MFC-AGG-ID: mTgAdLCzMdKHgGH5-KKyiw_1765491020 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-42e2d5e833fso260961f8f.1 for ; Thu, 11 Dec 2025 14:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1765491020; x=1766095820; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=DRrw2mEFcasOCUpxE3z89bZ0+erUgaOzx3WZhCZMjA4=; b=WsxV7v0jyTpaEJKSgZzu5chz23sEFydxO6dP7cZPMeqiqJxkWW9NdmcSXLxvyqxy9+ EdKqwnHOevZrPy3QjBm9HAs/uDpzYh3MPkQB/UpXSBVDt7HqCoqGmUP40WjyTsg709sx CLXmlhs607cHgd4EYkIUpVUs9fgO96vVBvOQZY49Ui0a1WK0SY6tyBztYXH7/mgr0Sas gR2VFb58r21uo0fscdpHNvP8pItag2lwRXJiwi5DuvWyvnuAHYa/WAatXWMSt86yohTP N6HIWSECwA5L/vl81czSMNg9bVx6mwQ122YXtMPuY4MKIxstoJ6aniqfq+L4yMIzxF3F lRgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765491020; x=1766095820; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DRrw2mEFcasOCUpxE3z89bZ0+erUgaOzx3WZhCZMjA4=; b=DSXWENbX0Vn3wqS6IniC5v3HiJUfai8X660miR8c6JDdV8VN3TpYNV6+9Br58W9sLc s4aZP7UybVEfvIY6a9TrYnpj/M3ddJziY/osESGDSA3XafAolJs//l8FHGlWVQ4JglSj Wx7/mRsnuOdM4jtzwISTHIgVBfpVkX8NkDwv+DlRQppdS8Xf+msAMGIC4rqjdlaat+dy LL/OnPBO/bq2gjlnDKJhBRn39OlWMG/2cCyEx58cJKUvfzAfDdEVv9+/Qhj+0vuLe4TG iN5Lw8McBfo7q3VPo7KEXqCXVZI+CE3JnfI9CDmFbUUS+HUFZiP3qsEjYwGgzfzWU1Zr eHbw== X-Forwarded-Encrypted: i=1; AJvYcCVDOTiCDyBbjAvzmvevSuhPtS5C/j2dc3PQ70apW6EEJ7/wgfhxvFVj8bCIIunasZQqobRz8r9xMCD1v1U=@vger.kernel.org X-Gm-Message-State: AOJu0YyxlA8rQJ76eoowSWFEaHyMjfvBsC/+5yjQ/+WaUBg9jOuD1Dut /ubYoqFmQajpgBLmuxYL2JpupEJlm/Y5Hfu4JCep3ojd6opXMHH0sP82IS9TwKKgwadQFcup1bE bg+Rnw5EBy+q5ujB//vAG0EC1uC0LSTTWMYsmswGoXcLMNcVIUCQawOBpkHtLaaRRtQ== X-Gm-Gg: AY/fxX4GkVdTLn0kAzEURSFxa1GmL8AfTQW7p7S4IUsWuhuMRyOReWUjKp92ZUIf/HF e9R0b4Je80fYXx18h3lEoAwhg30p205KrhE5M/BxGP/v1xh9z85zodm7Ifv/098U2ytfTGG62YN sx5tCFa2XMAXtj+Bqim/xYwiOAAKT3y1Ofl8yJ9kXKrbl/AwPtr2VkPeDa1/crQKY5cmQWKb9oW myt+hLFktjexJj4yXWT5FGWdlqyLMNexFA51XoijN3Ii/CZvUlyRrAq2no/Muq0CCqGo6I6HS+P 7eUnyPQjEKIF+eZ+10T+/GN0mbgYA4m/GugIIS7Cl4NuGBAZpn+ioyUDZDGJG9ch61Q1bsbRR20 PUYGhELLERCEX+ISr5s8ikrueOoYNyLh5942sFm1v7/ICDIWbVYd98ho= X-Received: by 2002:a05:6000:1ac8:b0:42f:8816:c01d with SMTP id ffacd0b85a97d-42fa3b1ef32mr7586040f8f.61.1765491020508; Thu, 11 Dec 2025 14:10:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFusB0V2Lib9x8KFjWMKFfd38tMcGVkGiclpC9vpvKusJCxtLUq3Q5ZipoVVIeu/ntr7EJIkw== X-Received: by 2002:a05:6000:1ac8:b0:42f:8816:c01d with SMTP id ffacd0b85a97d-42fa3b1ef32mr7586020f8f.61.1765491020099; Thu, 11 Dec 2025 14:10:20 -0800 (PST) Received: from [192.168.8.198] (pool-100-0-77-142.bstnma.fios.verizon.net. [100.0.77.142]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42fa8a665e3sm8220590f8f.6.2025.12.11.14.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 14:10:19 -0800 (PST) Message-ID: <678b25aba2bdb2e08818780f6ae16470e83fb8ff.camel@redhat.com> Subject: Re: [PATCH 9/9] gpu: nova-core: simplify str_from_null_terminated From: lyude@redhat.com To: Alexandre Courbot , Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter Cc: John Hubbard , Alistair Popple , Joel Fernandes , Timur Tabi , Edwin Peer , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Date: Thu, 11 Dec 2025 17:10:16 -0500 In-Reply-To: <20251208-nova-misc-v1-9-a3ce01376169@nvidia.com> References: <20251208-nova-misc-v1-0-a3ce01376169@nvidia.com> <20251208-nova-misc-v1-9-a3ce01376169@nvidia.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 (3.58.2-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reviewed-by: Lyude Paul 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. >=20 > Signed-off-by: Alexandre Courbot > --- > =C2=A0drivers/gpu/nova-core/util.rs | 9 ++------- > =C2=A01 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 @@ > =C2=A0 > =C2=A0/// Converts a null-terminated byte slice to a string, or `None` if > the array does not > =C2=A0/// 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. > =C2=A0pub(crate) fn str_from_null_terminated(bytes: &[u8]) -> Option<&str= > > { > =C2=A0=C2=A0=C2=A0=C2=A0 use core::ffi::CStr; > =C2=A0 > -=C2=A0=C2=A0=C2=A0 bytes > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .iter() > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .position(|&b| b =3D=3D 0) > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .and_then(|null_pos| > CStr::from_bytes_with_nul(&bytes[..=3Dnull_pos]).ok()) > +=C2=A0=C2=A0=C2=A0 CStr::from_bytes_until_nul(bytes) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .ok() > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .and_then(|cstr| cstr.to= _str().ok()) > =C2=A0}