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 2562FC5B549 for ; Mon, 2 Jun 2025 08:46:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8C1410E4BC; Mon, 2 Jun 2025 08:46:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="D4c2/cNz"; dkim-atps=neutral Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id 181BB10E4BC for ; Mon, 2 Jun 2025 08:46:30 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-450dada0f83so18544495e9.0 for ; Mon, 02 Jun 2025 01:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748853988; x=1749458788; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ktsVoxepsNTrdCKxowANypGkEb6jHKbHJKn1XhGy1Uw=; b=D4c2/cNzj+XvW0GUCMXR+gW/gWKxBEc1hodd5ZC+5dYg8PN2xcU7sDRmUjH+f7g2Pe uM02+YrBXwk2SJUfadN5DfB20LlwfWENrMMHLgTRrWrlQYvnPkXaeS1cK/DgwxAfTyls /l2Hbi1Co/fv0aV/FuCoWEDQOShD+ZJhJLJmMIQ/HsnQ3g+c8hPScpjroLwCfa8lKg3b 5sVumPx2EedS9f8SkvqOPBjqQQV/gKmZFTYFCm8+ZQqnVmxCVrm+Y9VO9qHvq1HPp9Uf WDXZLPNa4FQsYDZyg8lFAwpkUGF3JcNJ6QyTvybLbf4Bu2buNhVnRZgG61QVMPoFD3IQ DOfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748853988; x=1749458788; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ktsVoxepsNTrdCKxowANypGkEb6jHKbHJKn1XhGy1Uw=; b=uDbCr5rj3DUtBar/7WcjV4HHzVE3Dd4NJiCIwvKHg7urQBVuT7aI8qEAFcIC5f+ruU 5lXvRVQ3RuXvhY7Bt6soq7AS3bffLiBUDYRLUcFv3RQF2jTLkWzfAqShZi4e/qo/rxz4 F7uT6HNs715wlhUdkTxXrs0tf9XQAwoEaLPVDIsyEsGC3Ze2HgvzhDcCZPtNQumU/LEm WOVe8zApKXcZU3N/nFNgaeNHuZG5Ct19g029bbkKSiSVb9GSihmlC2QMIndsSHo0lytx qHF1n+5eWNdxLd1ZC6e2jFDTDTa/CdlrlJSM0nT89URtbakd3zMFXLrVQaAgFh5uOLzp bQsw== X-Forwarded-Encrypted: i=1; AJvYcCW6olmGR9OydacCwop1i7jde5hmFfXFunzTjkJCvRk6F1Q2WA9K5Cm+f8Rz7At/nzZBa2w+s1RP@lists.freedesktop.org X-Gm-Message-State: AOJu0YzoWXjqM8to7CKmnB+ekylJnGiY+hIHf9tKKysvXv2E7+8DweZN iddrgyu+lVkhDanU+jfiT+h0RFUtSFD2fZIwaRP6mjB5dGmACyzsiTBsbuC/LUzCwzltRBLiyT2 abOVqXfDX/m3RwdjDmQ== X-Google-Smtp-Source: AGHT+IEN8wW1H0RTzFbTdIlqYAJYXEVRMaA4cvq7c8CG74BNxW0QzTAmaWpfyWc/gO5HljzZUpfF3+rdjR1DcgY= X-Received: from wmbhc27.prod.google.com ([2002:a05:600c:871b:b0:450:d422:69f9]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4ec9:b0:442:ccfa:fa with SMTP id 5b1f17b1804b1-45121fb9373mr61377385e9.27.1748853988668; Mon, 02 Jun 2025 01:46:28 -0700 (PDT) Date: Mon, 2 Jun 2025 08:46:26 +0000 In-Reply-To: <20250530-cstr-core-v11-3-cd9c0cbcb902@gmail.com> Mime-Version: 1.0 References: <20250530-cstr-core-v11-0-cd9c0cbcb902@gmail.com> <20250530-cstr-core-v11-3-cd9c0cbcb902@gmail.com> Message-ID: Subject: Re: [PATCH v11 3/5] rust: replace `CStr` with `core::ffi::CStr` From: Alice Ryhl To: Tamir Duberstein Cc: Michal Rostecki , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Andreas Hindborg , Trevor Gross , Brendan Higgins , David Gow , Rae Moar , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Greg Kroah-Hartman , "Rafael J. Wysocki" , Luis Chamberlain , Russ Weight , FUJITA Tomonori , Rob Herring , Saravana Kannan , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bjorn Helgaas , Arnd Bergmann , Jens Axboe , Benno Lossin , "Krzysztof =?utf-8?Q?Wilczy=C5=84ski?=" , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, llvm@lists.linux.dev, linux-pci@vger.kernel.org, nouveau@lists.freedesktop.org, linux-block@vger.kernel.org Content-Type: text/plain; charset="utf-8" X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Fri, May 30, 2025 at 08:27:44AM -0400, Tamir Duberstein wrote: > `kernel::ffi::CStr` was introduced in commit d126d2380131 ("rust: str: > add `CStr` type") in November 2022 as an upstreaming of earlier work > that was done in May 2021[0]. That earlier work, having predated the > inclusion of `CStr` in `core`, largely duplicated the implementation of > `std::ffi::CStr`. > > `std::ffi::CStr` was moved to `core::ffi::CStr` in Rust 1.64 in > September 2022. Hence replace `kernel::str::CStr` with `core::ffi::CStr` > to reduce our custom code footprint, and retain needed custom > functionality through an extension trait. > > C-String literals were added in Rust 1.77, while our MSRV is 1.78. Thus > opportunistically replace instances of `kernel::c_str!` with C-String > literals where other code changes were already necessary or where > existing code triggered clippy lints; the rest will be done in a later > commit. > > Link: https://github.com/Rust-for-Linux/linux/commit/faa3cbcca03d0dec8f8e43f1d8d5c0860d98a23f [0] > Signed-off-by: Tamir Duberstein > diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs > index 2494c96e105f..582ab648b14c 100644 > --- a/rust/kernel/firmware.rs > +++ b/rust/kernel/firmware.rs > @@ -4,7 +4,14 @@ > //! > //! C header: [`include/linux/firmware.h`](srctree/include/linux/firmware.h) > > -use crate::{bindings, device::Device, error::Error, error::Result, ffi, str::CStr}; > +use crate::{ > + bindings, > + device::Device, > + error::Error, > + error::Result, > + ffi, > + str::{CStr, CStrExt as _}, > +}; Did you not add CStrExt to the prelude? > --- a/rust/kernel/error.rs > +++ b/rust/kernel/error.rs > @@ -164,6 +164,8 @@ pub fn name(&self) -> Option<&'static CStr> { > if ptr.is_null() { > None > } else { > + use crate::str::CStrExt as _; > + > // SAFETY: The string returned by `errname` is static and `NUL`-terminated. > Some(unsafe { CStr::from_char_ptr(ptr) }) > } Ditto here. Alice