From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 345B572634; Fri, 4 Jul 2025 20:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660167; cv=none; b=iF59tW4WeR+dt9hRSzwtGdE7ApUyjuc1Kl2sOOutHP370SRNo4EicYKkj1ozjIFeHwu+QBTEp8phQpS9sv2FiHwP78pOGRNBmIIGye9qNkJNem9bTS8294fFY18++kmUh5MUFYeQ/M1VEBUO8yV0l5OQSb8GJhbLJz1ke+//990= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660167; c=relaxed/simple; bh=0eE29d4BDbrbeYPny4FZm2lEWg1f3s4QbLWbmMdfS2Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XySAKcfWQzmaV88dsPTUVHIWE8aY+gPSP5rxMgVyRt+F6Of4IV56W8QuMV8VlZrlQo3Y999rwPfhezT0wwDEVm1h+iwJl66WtDdGUdi/F31ixu98iMhOEg9aE+39I4oESkUnsiPNClx6nMVNQJUF3+NkfVvkf/HJ7HqFFVi+gag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=blXEuRQt; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="blXEuRQt" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4a8244e897fso17298951cf.1; Fri, 04 Jul 2025 13:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660164; x=1752264964; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ytj/U1rka5vUlSmFzHnNuz0MRFUCm7uq4gnATea5MG4=; b=blXEuRQt/mqmEy2pdBvvcr4G5cWOyu9NXOK2l4VutbcfyWUp9b20W6HTIe0Np+PZWF EXGxgUHTg4tp9W3JSlr/WF7/+XKFWMs+5Xn6/qKXxR+d25FRHGMcydwjJjOfCKGmuqjP GvuH3zFAc2ISZY/aog+U/MVMeD3iIG3Is6hpGbIWZgFkvLvtWooqOTYoWANRVL4LzmX9 nS48+tjvLsRwAgZi72dfIAuIHrOTavHwGr+63LVhWgkDUYAk593oCaGL8xjntgG5npsO 06r2CqWMHl6UFRStItYQGGPbrUcLxt6qRudbW1s4hKeLY+xUfOtbeeZUi5oZUBiOGgCn 2bMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660164; x=1752264964; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytj/U1rka5vUlSmFzHnNuz0MRFUCm7uq4gnATea5MG4=; b=wFiB5hGOL1FJP0YRaj0Y7Zln0jodDbGH6iuiu0+Ftw4n7hEQm05ITDWDPIPW9q64qq CeuVpVhWIi1ZPZ/jHbVm8BQ0PgnPS2PNR7n/1JQoZLVZpZjG1RcW+FLrJMe2bTWsYCwj G0DwzESnTWF6ipzXvYONDCGpSy6fTho1n63Y4cuIVSK36SN0WuccFvuVqVj4Uy7pq6s8 ZTzBmjRvHfB+VHh29qVl4nu6E1czcJB7Bx5AMBXYcCh0VZJPkdyNdxfY2UlfJq+BWuTT YKY4sZr/sLoSre2FIB2q6K6yZE5EquPqmhMZtPpXxmdLzKSCidfaWqerLNy7YcuGTJir vExw== X-Forwarded-Encrypted: i=1; AJvYcCUT/zNofLwQVjR91ft80buj2dEAWPQ3p/ZELDGyUR9xt8Iv+eIsOMunu4yi1bUDTaZQJWZODa/O9LdyFygMfi0=@vger.kernel.org, AJvYcCV1yadPodH+K5hGmNFe6L8gObpnRFrnpJisB/pOpyjoxTheBfgqPAnZNgdJR5tnJwthpGBM9R97dUE+GYQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwqEd5BMeBMkG0zH09GsvTeGeX5J+U9JsGtJD7kUwMmbIQNSiIV fLsyb5CSu5rO7pUGQCNrx9CPsH568Bb5Vqcin8W0L/tq/xWfnGjXoYm1 X-Gm-Gg: ASbGncslkcjeTXk2u4Io8SBYQvKz4rzh7nDcRxHOAcJPzh1KdVKFfjYxcbELl8LCKV9 4XoTz8fIIXcfdqSfZbkfqTeknKscnenEQK0fyBykvRNl2lAPsWJ3hUMo8Lxeucnf05DzwbzxZnu QCv+wOINOgX9TrAFMRjvtt7yglxdifcYg9b4x2yszXL1Ji03S2KuHyCkS6/WhqIvGfpmQN/9ppW qBl+KnGnT33Z7XqwexfdIo2RntUPVGQfpRf7yIb6ebEvnb9zlIpWGnt7Az6OThKcJmR/dQHj4rH yzflt44Vqvvj5TCYCfJ5tFHVjC7mtMy/oViSlkynaNM1PVac97AjztSCeQANGGIWWbBb2zhvo7i gPCsxel4= X-Google-Smtp-Source: AGHT+IFEHuArpM8TIRSfH3/PNk3fgwhnpLrdJuiimaZA+jC0FuRTqewTYv7paL4gvO9Vh/4dQDMg8w== X-Received: by 2002:ac8:7e86:0:b0:4a6:c5ee:6ced with SMTP id d75a77b69052e-4a9a6d5f372mr751781cf.4.1751660163869; Fri, 04 Jul 2025 13:16:03 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:03 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:52 -0400 Subject: [PATCH 1/6] rust: kernel: remove `fmt!`, fix clippy::uninlined-format-args Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-1-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660160; l=8814; i=tamird@gmail.com; h=from:subject:message-id; bh=0eE29d4BDbrbeYPny4FZm2lEWg1f3s4QbLWbmMdfS2Q=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QBTfUwC+8+4Q7FidFkzWZ9u87I5aWLRGbg8aJnPxxBijaaEp1K9afxbrP+TMPnlXRRmGa9ue8Lk J89tQ+BdPTgY= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Rather than export a macro that delegates to `core::format_args`, simply re-export `core::format_args` as `fmt` from the prelude. This exposes clippy warnings which were previously obscured by this macro, such as: warning: variables can be used directly in the `format!` string --> ../drivers/cpufreq/rcpufreq_dt.rs:21:43 | 21 | let prop_name =3D CString::try_from_fmt(fmt!("{}-supply", name= )).ok()?; | ^^^^^^^^^^^^^^^^^^^^^^^ | =3D help: for further information visit https://rust-lang.github.io/= rust-clippy/master/index.html#uninlined_format_args =3D note: `-W clippy::uninlined-format-args` implied by `-W clippy::= all` =3D help: to override `-W clippy::all` add `#[allow(clippy::uninline= d_format_args)]` help: change this to | 21 - let prop_name =3D CString::try_from_fmt(fmt!("{}-supply", name= )).ok()?; 21 + let prop_name =3D CString::try_from_fmt(fmt!("{name}-supply"))= .ok()?; | Thus fix them in the same commit. This could possibly be fixed in two stages, but the diff is small enough (outside of kernel/str.rs) that I hope it can taken in a single commit. Signed-off-by: Tamir Duberstein Acked-by: Danilo Krummrich Acked-by: Viresh Kumar Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- drivers/cpufreq/rcpufreq_dt.rs | 3 +-- drivers/gpu/nova-core/firmware.rs | 5 +++-- rust/kernel/opp.rs | 2 +- rust/kernel/prelude.rs | 2 +- rust/kernel/str.rs | 34 ++++++++++++++-------------------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs index 30a170570c0e..4608d2286fa1 100644 --- a/drivers/cpufreq/rcpufreq_dt.rs +++ b/drivers/cpufreq/rcpufreq_dt.rs @@ -9,7 +9,6 @@ cpumask::CpumaskVar, device::{Core, Device}, error::code::*, - fmt, macros::vtable, module_platform_driver, of, opp, platform, prelude::*, @@ -19,7 +18,7 @@ =20 /// Finds exact supply name from the OF node. fn find_supply_name_exact(dev: &Device, name: &str) -> Option { - let prop_name =3D CString::try_from_fmt(fmt!("{}-supply", name)).ok()?; + let prop_name =3D CString::try_from_fmt(fmt!("{name}-supply")).ok()?; dev.property_present(&prop_name) .then(|| CString::try_from_fmt(fmt!("{name}")).ok()) .flatten() diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firm= ware.rs index 4b8a38358a4f..e503a4fddae0 100644 --- a/drivers/gpu/nova-core/firmware.rs +++ b/drivers/gpu/nova-core/firmware.rs @@ -24,11 +24,12 @@ pub(crate) struct Firmware { =20 impl Firmware { pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -= > Result { - let mut chip_name =3D CString::try_from_fmt(fmt!("{}", chipset))?; + let mut chip_name =3D CString::try_from_fmt(fmt!("{chipset}"))?; chip_name.make_ascii_lowercase(); + let chip_name =3D &*chip_name; =20 let request =3D |name_| { - CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}-{}.bin", &*chip_n= ame, name_, ver)) + CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{name_}-{ve= r}.bin")) .and_then(|path| firmware::Firmware::request(&path, dev)) }; =20 diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs index 0e94cb2703ec..5a161ad12bf7 100644 --- a/rust/kernel/opp.rs +++ b/rust/kernel/opp.rs @@ -345,7 +345,7 @@ fn drop(&mut self) { /// impl ConfigOps for Driver {} /// /// fn configure(dev: &ARef) -> Result { -/// let name =3D CString::try_from_fmt(fmt!("{}", "slow"))?; +/// let name =3D CString::try_from_fmt(fmt!("slow"))?; /// /// // The OPP configuration is cleared once the [`ConfigToken`] goes = out of scope. /// Config::::new() diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index 2f30a398dddd..3ca934885797 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -31,9 +31,9 @@ // `super::std_vendor` is hidden, which makes the macro inline for some re= ason. #[doc(no_inline)] pub use super::dbg; -pub use super::fmt; pub use super::{dev_alert, dev_crit, dev_dbg, dev_emerg, dev_err, dev_info= , dev_notice, dev_warn}; pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr= _notice, pr_warn}; +pub use core::format_args as fmt; =20 pub use super::{try_init, try_pin_init}; =20 diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index cbc8b459ed41..10399fb7af45 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -54,13 +54,13 @@ impl fmt::Display for BStr { /// Formats printable ASCII characters, escaping the rest. /// /// ``` - /// # use kernel::{fmt, b_str, str::{BStr, CString}}; + /// # use kernel::{prelude::fmt, b_str, str::{BStr, CString}}; /// let ascii =3D b_str!("Hello, BStr!"); - /// let s =3D CString::try_from_fmt(fmt!("{}", ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{ascii}"))?; /// assert_eq!(s.as_bytes(), "Hello, BStr!".as_bytes()); /// /// let non_ascii =3D b_str!("=F0=9F=A6=80"); - /// let s =3D CString::try_from_fmt(fmt!("{}", non_ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{non_ascii}"))?; /// assert_eq!(s.as_bytes(), "\\xf0\\x9f\\xa6\\x80".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` @@ -85,14 +85,14 @@ impl fmt::Debug for BStr { /// escaping the rest. /// /// ``` - /// # use kernel::{fmt, b_str, str::{BStr, CString}}; + /// # use kernel::{prelude::fmt, b_str, str::{BStr, CString}}; /// // Embedded double quotes are escaped. /// let ascii =3D b_str!("Hello, \"BStr\"!"); - /// let s =3D CString::try_from_fmt(fmt!("{:?}", ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{ascii:?}"))?; /// assert_eq!(s.as_bytes(), "\"Hello, \\\"BStr\\\"!\"".as_bytes()); /// /// let non_ascii =3D b_str!("=F0=9F=98=BA"); - /// let s =3D CString::try_from_fmt(fmt!("{:?}", non_ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{non_ascii:?}"))?; /// assert_eq!(s.as_bytes(), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` @@ -429,15 +429,15 @@ impl fmt::Display for CStr { /// /// ``` /// # use kernel::c_str; - /// # use kernel::fmt; + /// # use kernel::prelude::fmt; /// # use kernel::str::CStr; /// # use kernel::str::CString; /// let penguin =3D c_str!("=F0=9F=90=A7"); - /// let s =3D CString::try_from_fmt(fmt!("{}", penguin))?; + /// let s =3D CString::try_from_fmt(fmt!("{penguin}"))?; /// assert_eq!(s.as_bytes_with_nul(), "\\xf0\\x9f\\x90\\xa7\0".as_byte= s()); /// /// let ascii =3D c_str!("so \"cool\""); - /// let s =3D CString::try_from_fmt(fmt!("{}", ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{ascii}"))?; /// assert_eq!(s.as_bytes_with_nul(), "so \"cool\"\0".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` @@ -459,16 +459,16 @@ impl fmt::Debug for CStr { /// /// ``` /// # use kernel::c_str; - /// # use kernel::fmt; + /// # use kernel::prelude::fmt; /// # use kernel::str::CStr; /// # use kernel::str::CString; /// let penguin =3D c_str!("=F0=9F=90=A7"); - /// let s =3D CString::try_from_fmt(fmt!("{:?}", penguin))?; + /// let s =3D CString::try_from_fmt(fmt!("{penguin:?}"))?; /// assert_eq!(s.as_bytes_with_nul(), "\"\\xf0\\x9f\\x90\\xa7\"\0".as_= bytes()); /// /// // Embedded double quotes are escaped. /// let ascii =3D c_str!("so \"cool\""); - /// let s =3D CString::try_from_fmt(fmt!("{:?}", ascii))?; + /// let s =3D CString::try_from_fmt(fmt!("{ascii:?}"))?; /// assert_eq!(s.as_bytes_with_nul(), "\"so \\\"cool\\\"\"\0".as_bytes= ()); /// # Ok::<(), kernel::error::Error>(()) /// ``` @@ -578,7 +578,7 @@ mod tests { =20 macro_rules! format { ($($f:tt)*) =3D> ({ - CString::try_from_fmt(::kernel::fmt!($($f)*))?.to_str()? + CString::try_from_fmt(fmt!($($f)*))?.to_str()? }) } =20 @@ -840,7 +840,7 @@ fn write_str(&mut self, s: &str) -> fmt::Result { /// # Examples /// /// ``` -/// use kernel::{str::CString, fmt}; +/// use kernel::{str::CString, prelude::fmt}; /// /// let s =3D CString::try_from_fmt(fmt!("{}{}{}", "abc", 10, 20))?; /// assert_eq!(s.as_bytes_with_nul(), "abc1020\0".as_bytes()); @@ -930,9 +930,3 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Resul= t { fmt::Debug::fmt(&**self, f) } } - -/// A convenience alias for [`core::format_args`]. -#[macro_export] -macro_rules! fmt { - ($($f:tt)*) =3D> ( ::core::format_args!($($f)*) ) -} --=20 2.50.0 From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63F7222FAC3; Fri, 4 Jul 2025 20:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660167; cv=none; b=jDcLQj+Qstd2OAYAdcENydsUnJHbdi0W7gqMCVo3EhhdQO/SnipzDYWJUp0HL0oBatG1FGIvVdPqWsDRvbB7+UVzFsp6xvLkUQdW/gMjSPR3utelL9CmcYSKV4dK/VJ+YoEdG9hfZqljamRymPQc2FCJcSkRdXXfmGXO48yWcAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660167; c=relaxed/simple; bh=mJsS2vyiaMWiPQwd7tQN5gQccE2lmw3c6g9maEbaKdQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cvVyMGySf59Rv4kSa2nmOFoPz0szosvZyVn4UGPNSZPxsUJsle4cLMZ/GWgaqtBY9BUa2D/jrdQjR3Om54zHdsGk7MxqvKziQNqCGnS/Dia0TS9IedVGpMcqaIiySpZNbhJHFE57BD5m3KRTUMKTFTyajUNxa6sS+yv8qod4nhY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HIdRfwjh; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HIdRfwjh" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7d5df741f71so82910285a.3; Fri, 04 Jul 2025 13:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660165; x=1752264965; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a8gKMhK1P8kYlXeRydF9g6Ir5n6qoRzHtME7/jbZwh8=; b=HIdRfwjhpY9nQnxjgWjliRaByNHiSBC4tfqczWTOcaYl7lFbIuHVFs+waeAUctN83K ndOJJH7MpmSOe7Wf0pMT9c5sU5E+316h3w93JyS+aD4ekikZvErjPFkMEhNgaVfDdTyb opWnM9K5YSvsCXm0o8RNanO9+RXmG2Rn2dUQzrATifQ93De4YNzIyYFhZJgX4YZ89LTq 3aoF+qL1K3QXLCjB42u9dx0sHaKH2TQ2TmZx6FznL2qFXW6EA3qZvYqMA+xR5KnHoK2N wcy2zr/TQAIJSzW5kKJLuy6Bwa4dIANPKNbfsfBym80D68063AUmOcEs6EYXmCLPqfUp 3U9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660165; x=1752264965; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a8gKMhK1P8kYlXeRydF9g6Ir5n6qoRzHtME7/jbZwh8=; b=a6dxoS7qGqG9Pry3pGI9goAISBnNzjMSmsABF/UMUy4vrR4ohknLBJtUC7aRb518ta AinIMaw5iMor/lTGLZ+kC5zUk+GCVEAI6YujrEliIqoAkyl1l2umLJPdrZSYHTzKOP1q sw8jXV+8gr/S+322qSgzJfg6WOqGIqfDrYsq+yDVxWnsHyW/lel8c4+XCRecQvNm8uw0 iO9McFOwNCKdnqrov7i3WMX9tTnfwikGCCUZnjMwkoo81UJbswlXCrbldoJuGbyovrq8 GpoNeWGJflHRuRVuya8Q1gQMCP07+ACgRgDFu+2SAMsl/4UTN+iLyxAjI66idOSIC04b 5fZA== X-Forwarded-Encrypted: i=1; AJvYcCUeRd4cd4s/TM8rihuKzb3wv3gYmq9fU56I8o0EgaRWiBlOW/w1SgFcVmsf75DfpvgGcaxPKPr7eBjR44M=@vger.kernel.org, AJvYcCWIHSVCoNT7cBsyU04YDEZXXTrhKsUCt8sAwibhRuT8gDxf9xZ3VyO26C7+hTnLhd6joY7gTsRJRXU+DwKO6hk=@vger.kernel.org X-Gm-Message-State: AOJu0YzEuLuqOpw4O2i+uXBSGjXgtUni78xqMyJYKGH+ZQS+Ew8dcF/I HVvXWr3IpxzNXotVt6TbWJl67uRHDnU1WY5tY4a5e2HijAiLRC5H3jf8 X-Gm-Gg: ASbGncu5d9ga8t5enCEhlesFUlpOJvziDnpNVOMUCHYGjVmCey2UIE2a/J550HOu3UU VMOBMUiqc2XXJRZ6Dq/tAQn8Ig5af2NLLgQ3mebtE08CGUyhxAlgEK122qM2IQZi+sFI66A4lei bVkUVmhEptc8kkbx2DmV/fZZI5PEnCw0rWupiyDUrY40i91GX8z3poyBVw6fT+VCHoKu+vW+v4k QqEa5Dzx2QxvBugTaRfQ7imqMtqy8ft6b30V9pb8gNEzhx0iMGmmalbXLkw43TeI8VAcJma4Y4o p8vlvAmqWLM3ewK/CVg+PskkNAEb9R19soLHlDtWS+hiyJCgfBXWBF7V1GQ0wA641boIROHRA/j mlmCSoBk= X-Google-Smtp-Source: AGHT+IF8p2jozIXmEQ2f+bxDZzizA3OOtjH7naor9ZhxgadHOKRJrT3ao5tXDNlKY8MPWMKo8J986Q== X-Received: by 2002:a05:620a:370f:b0:7c5:4278:d15e with SMTP id af79cd13be357-7d5dcd0b203mr506984385a.33.1751660165283; Fri, 04 Jul 2025 13:16:05 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:04 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:53 -0400 Subject: [PATCH 2/6] rust: kernel: add `fmt` module Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-2-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660160; l=1102; i=tamird@gmail.com; h=from:subject:message-id; bh=mJsS2vyiaMWiPQwd7tQN5gQccE2lmw3c6g9maEbaKdQ=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QG3gvXbICtoQcnka1UGwT4DQfnT07Ks8Lh3dK1e4qeI8hb+rSV4UlssrsjJhEtHgZyeSB31xbBA 926txUPuxKgU= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc `kernel::fmt` is a facade over `core::fmt` that can be used downstream, allowing future changes to the formatting machinery to be contained within the kernel crate without downstream code needing to be modified. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/fmt.rs | 7 +++++++ rust/kernel/lib.rs | 1 + 2 files changed, 8 insertions(+) diff --git a/rust/kernel/fmt.rs b/rust/kernel/fmt.rs new file mode 100644 index 000000000000..0306e8388968 --- /dev/null +++ b/rust/kernel/fmt.rs @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Formatting utilities. +//! +//! This module is intended to be used in place of `core::fmt` in kernel c= ode. + +pub use core::fmt::{Arguments, Debug, Display, Error, Formatter, Result, W= rite}; diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6b4774b2b1c3..aadcfaa5c759 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -77,6 +77,7 @@ pub mod faux; #[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)] pub mod firmware; +pub mod fmt; pub mod fs; pub mod init; pub mod io; --=20 2.50.0 From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8B8823BD1F; Fri, 4 Jul 2025 20:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660169; cv=none; b=OPMo5cgQ8rlFP56T+F9SCMcIqpsM4rXTWjsES7fk9ZybKNbIHMVfOQ/TzHOjmz6Sn/++sj3inhZBdDwQRNMO6WPHVkPCAPbeZ5kmcJz2F/8tySfbHs5Y/gfXm0xjgs0jeWVHD2HQE+BTSKk2Mm4u/N19oU1tHkkde1ps9sbZisk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660169; c=relaxed/simple; bh=pDl2EDPfxPEYVWR9FNKoe/jjP+2a7nwmEQia5/vDvaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PTP+X26Pix4moDpdY5hkauDtJQvigcz71wYjTyCmel7d+sqEJla4s+tQaG4RXWcazoQ4+QwmKwjkxkaAI0yMscxjo8pM2zCNMHY5J4d604gAxEL1Y09KorjNEsgLuJqExLm2A/DPR36V7MhhSVFzmnDQcfA8BaehRsiACIkJ1J4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WcWytZQJ; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WcWytZQJ" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4a76ea97cefso13098201cf.2; Fri, 04 Jul 2025 13:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660167; x=1752264967; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IjAX5By1woBTkVbpv4Ax05fTUisbOPE+2UGRU9+yRbU=; b=WcWytZQJ6vpFCLHH3jz9Cqtk2fgeopjU6zHk4kx4YlAtAgS/YY3hg/Gsic23CW9IfD q4I4t8N73ukzyAbmO+W7j8ECMwoNVy3DdNz1WVIyNzBfxNGvEYM0vhp/CKXsDETDyVzC RrwhoqtRAdWHoNDfs/jXKvD0/JCf3PRUS6E7rNw59XGHt2cIV6c1mxH5BYLje2VU4jpB 8Pr1NmJv9DinMTqLMrye/0z5/I0k09A53hAWb2G2su0YOOlOG7hK0axm6TYYNc17LCDn HhFbxcY/FI5t2WHFQqxu3ECNdonVn0nbPhvzKFKnLF9Q+GfFZDqjxtvTRL6HXDCPtcgA 4xTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660167; x=1752264967; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IjAX5By1woBTkVbpv4Ax05fTUisbOPE+2UGRU9+yRbU=; b=OaPnyVucBBxfVnt/DZXV0ucz4OKrxWdmuX1riXdasozZQtv3yGbqItNJkr3NerN69v lSm8xve/FHTqXyXZZnPGsTQIjv/v1xVKONHwjfRQf/ocFOsSbx5XMLnxqXsI7HN60CFD VTdmcVBCsP0YwPieIYAvorxEVLPRo7Sc3eDPILG97RdpQ9868fPrzWQ1mFdqe/m8qOHO APYACgT9UtbMVqKOBAmBZ/EibU+2NKW4xS40+IPHM6SJzYR2lqmt8LPY2+DStYD1HD2U D5CIw83u9SQpe3PlRWt7AlYCiA/W9OUaCnXLntWB8Ote4VmSJriRY54gxGIOjUpIoRg/ NHWA== X-Forwarded-Encrypted: i=1; AJvYcCUwW3L4553Y+Ku+g/EuwdX7ZntOUjqzbT0Nh1OaHhss4Gn5WJKt5vMVYFkVTCT6tzoXfzZL9JMnnmyEkKc9wlM=@vger.kernel.org, AJvYcCVxnk3ZmTFlj0Lub0Rc6/JAmd9NdoFQloF9nNfFWT1NwLk17ZLQXi7IdlgokOq/4/EFLoC1QdL6O6oGfwQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxQVyhMlZ4kt+2X9gG2OQa/SUwazXDkhce2vlfEExQWEJ9+BqYo tChmtDCrM9Y3TnFaZFscYLvJyR0x77LsWX5vv0+/2VMA5leldsE7ETMy X-Gm-Gg: ASbGncvBfnUeqfHQXyqeM2n9q2Ol5SsK63vag7QkmYmk4JzTxg1I7gYjgGTAUMYA3tt 1hxwnCkUGHA+qRMxUsldoIvA36DLVP65kEJHsE0dSs2lEs2tfU/SY55Z91m54EBpRLEPrS/pfd+ 3YdztZ94x5PTlJdnESU2faxUyeBhRoIyjEVOifu0O/I3ukQv0gjKolrA3G4/q3XJRBxGe4j1j3A N+JoTjXfT02zlir3yzb+2F8zVvhPUuwnadXkGvlWT84QfYJbDI22DgGjTrgkvLSnJtUSXIwDsNG GIgvjOYM4NttyNafKFJLwXWcOyzadMi9WfiVx4qhIWYHPxbhymBNvChwsIAvOP7vLXcZ1szArhL 0re2EfKo= X-Google-Smtp-Source: AGHT+IHoJuyrMg+1Oet7D/5z8M7VsWfC8gsB87eCJncM3DAyTr2cIYU7OHvXVugATk7u3p3qiIn2YQ== X-Received: by 2002:a05:622a:316:b0:4a4:4063:94d1 with SMTP id d75a77b69052e-4a9985e0c0cmr42987461cf.8.1751660166573; Fri, 04 Jul 2025 13:16:06 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:06 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:54 -0400 Subject: [PATCH 3/6] rust: use `kernel::{fmt,prelude::fmt!}` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-3-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660160; l=3354; i=tamird@gmail.com; h=from:subject:message-id; bh=pDl2EDPfxPEYVWR9FNKoe/jjP+2a7nwmEQia5/vDvaQ=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QCBuyGbM9Ex3z6w+I8XsfYWnnt5RfWTJc8W/D+LryP6sut6ti1h3WTUJlGdh3zPO073i/ELXAnX ilrfpP+tUvgE= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Reduce coupling to implementation details of the formatting machinery by avoiding direct use for `core`'s formatting traits and macros. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/error.rs | 6 +++--- rust/kernel/print.rs | 6 +++--- rust/kernel/str.rs | 2 +- samples/rust/rust_print_main.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 6277af1c1baa..ffa8efd2d547 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -6,10 +6,10 @@ =20 use crate::{ alloc::{layout::LayoutError, AllocError}, + fmt, str::CStr, }; =20 -use core::fmt; use core::num::NonZeroI32; use core::num::TryFromIntError; use core::str::Utf8Error; @@ -219,8 +219,8 @@ fn from(_: LayoutError) -> Error { } } =20 -impl From for Error { - fn from(_: core::fmt::Error) -> Error { +impl From for Error { + fn from(_: fmt::Error) -> Error { code::EINVAL } } diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index ecdcee43e5a5..2d743d78d220 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -8,10 +8,10 @@ =20 use crate::{ ffi::{c_char, c_void}, + fmt, prelude::*, str::RawFormatter, }; -use core::fmt; =20 // Called from `vsprintf` with format specifier `%pA`. #[expect(clippy::missing_safety_doc)] @@ -149,7 +149,7 @@ macro_rules! print_macro ( // takes borrows on the arguments, but does not extend the scope o= f temporaries. // Therefore, a `match` expression is used to keep them around, si= nce // the scrutinee is kept until the end of the `match`. - match format_args!($($arg)+) { + match $crate::prelude::fmt!($($arg)+) { // SAFETY: This hidden macro should only be called by the docu= mented // printing macros which ensure the format string is one of th= e fixed // ones. All `__LOG_PREFIX`s are null-terminated as they are g= enerated @@ -168,7 +168,7 @@ macro_rules! print_macro ( // The `CONT` case. ($format_string:path, true, $($arg:tt)+) =3D> ( $crate::print::call_printk_cont( - format_args!($($arg)+), + $crate::prelude::fmt!($($arg)+), ); ); ); diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 10399fb7af45..48d9a518db96 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -3,7 +3,7 @@ //! String representations. =20 use crate::alloc::{flags::*, AllocError, KVec}; -use core::fmt::{self, Write}; +use crate::fmt::{self, Write}; use core::ops::{self, Deref, DerefMut, Index}; =20 use crate::prelude::*; diff --git a/samples/rust/rust_print_main.rs b/samples/rust/rust_print_main= .rs index 8ea95e8c2f36..4095c72afeab 100644 --- a/samples/rust/rust_print_main.rs +++ b/samples/rust/rust_print_main.rs @@ -40,7 +40,7 @@ fn arc_print() -> Result { // behaviour, contract or protocol on both `i32` and `&str` into a= single `Arc` of // type `Arc`. =20 - use core::fmt::Display; + use kernel::fmt::Display; fn arc_dyn_print(arc: &Arc) { pr_info!("Arc says {arc}"); } --=20 2.50.0 From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1823E243968; Fri, 4 Jul 2025 20:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660170; cv=none; b=pt04eCre8gg/XZenLEwnnjiiKsTGATu6fYqfL3EVUc6pkdZwSIpNw+QaH2XdtG7z26cEmnKuIkwzv52uJvyndMbo4DhhB4oQWC2w0Q8xZhWDSvtKjAClp9Jjy4TAGcaf1YFZrf1r4o7b9z7khsAsBQswan36G37u2fgYoT/YvSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660170; c=relaxed/simple; bh=sfKyAlpcVUQy80XFUpORKTGMx+OCz/EQm3USwht0+Yk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LBVl/L3/Gy+oxIbe3ZIIK1UE42zpS5Y9FlAOTMOHqlLdO2RJOr394U7r5uBhBeKhjilY0NQylx1ZTvD15mKfClqvyGyJAMVPKVrnmeG6VD0+W9MF3Wx9qcKRHNwTBFO8c2oNPOTLDLLRugTwC8t7K60I/hwWJGrZD2M2W4qZ+w0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SP2YTKq3; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SP2YTKq3" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4a7f46f9bb6so16359141cf.3; Fri, 04 Jul 2025 13:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660168; x=1752264968; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JftnGw2ieRIMfPF9FeFktko6aUdoxCz5p+LPiScYnD8=; b=SP2YTKq33IIDli3LjBuPMnhxmTlzpPTD/XS9h52j2n+SLAghxLIpEAOqKqv4NJ5exp XGrgexzDBbM8M8ccQBYlR1NeupHh8ES6MZ4M/CrcKMzbUL9EybrjbwGl2zo6xBv51EfF uf8BCFSZC753pU2bB1xckM+7JZEv6bin/jokbgCLTf3KubMzwR6QF/fKmO2M7B3QXPcj fkBoJJogeu3m8c0562iU5GEPePu21IRjquAQsRO292QbmPo7ti0v/Sc8A9dAN7WVtQmY MxggIR2zZA889pI6Zid7YDCIFawQgnUQupjumCuYhn6N0LJYGlecHHjK/c+tgSXqkfTW vPDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660168; x=1752264968; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JftnGw2ieRIMfPF9FeFktko6aUdoxCz5p+LPiScYnD8=; b=hxSzNwXTvxTGjKgCKUp/Y7bT0ROznMVdy9LpsMvBhRjsnpw6CZaJgcWcnnVE5XBTd/ JDJNMl5dtS/oU/l/rvnmhZmrdhbk/JsdfUjQBRoAisQ4xExPcwJ+Xd2urrjZchz7aVDU JJXGTP0pPaEivVyhsJ2xHUypt2Z2l0v1sRGv9M47YJhBmef7gCul4jWJBjEXzjrDHqcY JAns3ooZ6f3MjLqDtdGgLNlOpRNVFaxN1s2CHS7vvP7DD944SJKK3zN0yrQMbNdx6wcq etmZBWoJzIsghQzp9bf+xN7Y32ndY5ligL10QjHjz60YlzUJeXZETHdvVYOhAHctdrEY CzSw== X-Forwarded-Encrypted: i=1; AJvYcCUyfEd3mn2xu2b5Q+LYs95ifaci7houZDEYVK+brrmmGyWPqgChpcIEL44mGg1H8vie+BsKmhlvxtx2LQuwmXM=@vger.kernel.org, AJvYcCVupvMl9TtrqgAD2qWqVa7hoWW+tKeOKpRs2AvnSZaQjzPfm5ec4/PDdAQjpbP0nusgLOr5ScW5xhCmnW8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2NyGckBPUaK5ixtHQFxI6qpnc1PtxJXKXOud3mxNZAwKW5GDc +JgYByqfLPkyBwbkp3IorcqYWZKDKvQcxk4RI9Ltham4/JWkpQWkh4LW X-Gm-Gg: ASbGncshw3sD4K0n3eBD/V0I8a1Ol1s2vEcXP/zeQnGG5l+X3LNFvuobhOeC29sSLC0 P2v8UEUssXH8kBrNo4gmYtbfYdrfbHkwXSU4EWsc5Pl6bn+xM5fsk/0nAuh4irlWiEZQpAwSy0y rxjABPcdpdqriQUsD7Ho2JRd7bfnjU8LnS2Sr+Uqe/Bbt1REACALlUmkRfiMLD8gbsm3nezo1a2 oV2/0/xTa9VBHJhi3AqIrYX97lh9nkBGI7Jzd/y3vDsn12dwsJPZg9iyrNMgWRgD1aDiLxPV7ib MKQHZN4+pVjbGWiqdj081aOUQgUTbetIJa0feinW0GPrztOJPPTHoD3HBVxrLsFY1V1vLsqvy4Z J2b7aQHuBipmFzfZY+A== X-Google-Smtp-Source: AGHT+IF1t1aKHOe1fk9iSK6MMX3BAmHjjyKwyg4+tGB5Y4Nti+Dmbb5QN0nFVxAZPfxMG3QwhMXk+A== X-Received: by 2002:ac8:5fcf:0:b0:4a4:3d6e:57d4 with SMTP id d75a77b69052e-4a99883ca50mr51364261cf.46.1751660167869; Fri, 04 Jul 2025 13:16:07 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:07 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:55 -0400 Subject: [PATCH 4/6] rust: str: remove unnecessary qualification Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-4-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660160; l=1218; i=tamird@gmail.com; h=from:subject:message-id; bh=sfKyAlpcVUQy80XFUpORKTGMx+OCz/EQm3USwht0+Yk=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QHvRIVvJtq07S1R75iYq2AMmkTap/2F2AhnqArHL10X6H2X/PDdiObvGpzgmEBt9fR6VL1UeMvw 7vloZt88VjAw= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc `core::ffi::*` is in the prelude, which is imported here. Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/str.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 48d9a518db96..f326f0c40ab0 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -232,7 +232,7 @@ pub const fn is_empty(&self) -> bool { /// last at least `'a`. When `CStr` is alive, the memory pointed by `p= tr` /// must not be mutated. #[inline] - pub unsafe fn from_char_ptr<'a>(ptr: *const crate::ffi::c_char) -> &'a= Self { + pub unsafe fn from_char_ptr<'a>(ptr: *const c_char) -> &'a Self { // SAFETY: The safety precondition guarantees `ptr` is a valid poi= nter // to a `NUL`-terminated C string. let len =3D unsafe { bindings::strlen(ptr) } + 1; @@ -295,7 +295,7 @@ pub unsafe fn from_bytes_with_nul_unchecked_mut(bytes: = &mut [u8]) -> &mut CStr { =20 /// Returns a C pointer to the string. #[inline] - pub const fn as_char_ptr(&self) -> *const crate::ffi::c_char { + pub const fn as_char_ptr(&self) -> *const c_char { self.0.as_ptr() } =20 --=20 2.50.0 From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62AE3248869; Fri, 4 Jul 2025 20:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660172; cv=none; b=Bipo5bGVlp+mHy3Ko4Zq4prKWtVEfwruWQ2gEPCab8L3Zd1aEIbBWcSsFvwUyOjGQonSo2fprgcCubcqm2GR3l+H7vG5P1oKVFkzFykJOeDNUk6ZFWO5k1qMjk9xxISTcbquEGdWWh1+WDc++4XXjMazTMllUg7uP4f6nl02uvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660172; c=relaxed/simple; bh=ijekkld9R1wbyb2cvN5FAg3adFOAIGh+Sl7Wg4UqSo0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Lsz/iMQQ5U4+Ils2FSDHD1NyEeiQp4Gd2Z6sMIwlQdfdGM+ghkGIBS/WLqK5T9LTpYFs68gRrX4zCMrparHGDOYUD47u0JlIUgqstZ8yYOWxmcKVhEz6gm9pv1UjLxljAGUw2/Op+jXBL2LxnyLNES7VBkA1nQbzps+qBChxPVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=crpE/EXe; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="crpE/EXe" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7d3f192a64eso132349185a.2; Fri, 04 Jul 2025 13:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660169; x=1752264969; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RRnCMuqdD131ZlyvTYi0z/+zkxHVEj8TfOGSz4lWZYk=; b=crpE/EXeigqrL9AXm0LvpeWZ3f4YeYwMUH0UGYbNjx7EEcvbbB8UZRdcVN8u1PiyUW qA4+tXOyvk5x/AgzD3q0XpGw7x23BsSAvqSVXKExETqFKYuwVRLbHbkuJ1NSgBEKmy61 YjWhsOzKmqh0aIekPcxN0xpBL4w7VMAlJRvCKPC8AHXy/PNYFuJYlQvJ6MHyVcf1POyY vj7YulU6uMgztIFCsZKjw9K3UybqRkZcPjqP+ADw1qPPi6yr/L0HBjHU+P7JH80f0CI7 JxzeT6dm6RWS+9YWlZkDgBjlpaT2RiFeEbtpBlJJQq8tTryO8Aglkpk4ZwE294arg6bl JKdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660169; x=1752264969; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RRnCMuqdD131ZlyvTYi0z/+zkxHVEj8TfOGSz4lWZYk=; b=cn2iGZy54veR2iIDH6XtnuUYk3iMG+ynaRIznV0+dbsTU3AgCmZTTB87pbLrLBGj1V yTVJITbqcAcLMsE/+P8fVKNXjcQOOXnMitJu0Jf+7nl46OatxbNMHxDNJZ5gQL8wQ4aL rO8ak7BFIudBuva2k81HQjOVXt47VDi0ppJsHg7CnUcP0kPjOmngwAHrCPL9Jq5jxjc7 Hxbfl7Khbd6dDSH6wUsEoh5BgKiSOirWshxCj0SzF77EQ1/jZlVoWa5wF+uRzI2ZKhGN c6mOWftGapRrfgVf5olcWb8EKPkDqhQP/OuWQMF6sfAaqvZ/uEr0llpRZuZbVDNJUdR+ UQEw== X-Forwarded-Encrypted: i=1; AJvYcCXH2XTXh3tL0o8WdIizAwa7ogfWuNMgD2KMU1x2c7O3ZRXCnT6zwOynRzcxazo/w/bnYRODCWYsFqH5j9cEB+I=@vger.kernel.org, AJvYcCXpNahRGIIraZ1G5v/ItPDZZMowuAYVsrX542UISagO+bBCIHZIwysMxqUHU9WiD2OYa1cEfxFjSAoUs/c=@vger.kernel.org X-Gm-Message-State: AOJu0YwayKl1gudcAyj9dlkndykIb3+zXfZADQjii+dPrDXQjA7vff82 eDrDRH3xfRVQdTUPm/UnsQm+vVR/JZIDE9eAy4JcTeK3fsSiVBVB+/NY X-Gm-Gg: ASbGncsXZJmvoXRtGT1VuoeiHGint9IjPVAhCUByY9ot869jNs2ugZ7FpfwPcBtDZoa mzuwaMNMUH6CVu1U+VuZcytvBIQan5S/qKm2w5nKu0rUdT+Pc12FeqZEhkmCZzzsZBoAORustgY PpDByI655rn7221akMXmva9ZhirNVbV4l1rpFyppkkF2EkCP9vchiekD5AElUwWpIPNU5MPEjyc RwXbLlpFUFXkM62JPzYT+STuHtcPrEyzDkDiD2idrSzjnXwO0ne+eH4Ei8jkODURcPbox5NgxRz r1/VY8mRQJNkvmvwjIofQ1rAiNIi47J4blwmtG6MN6xvbE8a2UQd87TqtC6eleYiC1wExIpRZQb ppg3PdvI= X-Google-Smtp-Source: AGHT+IEPhl7M3pPKVKJRRGXgxtNYr3mSuepsFyT/fNiRn/kJBm9O1QrZ8LLvefwHdmgY4q+idaONGw== X-Received: by 2002:a05:620a:4456:b0:7d4:2925:91b8 with SMTP id af79cd13be357-7d5ef7c4961mr28485585a.16.1751660169087; Fri, 04 Jul 2025 13:16:09 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:08 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:56 -0400 Subject: [PATCH 5/6] rust: add `CStr` methods matching `core::ffi::CStr` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-5-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660161; l=3187; i=tamird@gmail.com; h=from:subject:message-id; bh=ijekkld9R1wbyb2cvN5FAg3adFOAIGh+Sl7Wg4UqSo0=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QPIwxczA1HLqncTECE1BZLwn/UXLVbajrq24i9LGs2u/GwbE2mHvzVz95Yp9yW1WgfD35PH8Hrr KgvLRh39BRgE= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Prepare for replacing `CStr` with `core::ffi::CStr` by soft-deprecating methods which don't exist on `core::ffi::CStr`. We could keep `as_bytes{,_with_nul}` through an extension trait but seeing as we have to introduce `as_char_ptr_in_const_context` as a free function, we may as well introduce `to_bytes{,_with_nul}` here to allow downstream code to migrate in one cycle rather than two. Link: https://github.com/Rust-for-Linux/linux/issues/1075 Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/str.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index f326f0c40ab0..cbb357fc0111 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -175,6 +175,15 @@ macro_rules! b_str { }}; } =20 +/// Returns a C pointer to the string. +// It is a free function rather than a method on an extension trait becaus= e: +// +// - error[E0379]: functions in trait impls cannot be declared const +#[inline] +pub const fn as_char_ptr_in_const_context(c_str: &CStr) -> *const c_char { + c_str.0.as_ptr() +} + /// Possible errors when using conversion functions in [`CStr`]. #[derive(Debug, Clone, Copy)] pub enum CStrConvertError { @@ -294,23 +303,45 @@ pub unsafe fn from_bytes_with_nul_unchecked_mut(bytes= : &mut [u8]) -> &mut CStr { } =20 /// Returns a C pointer to the string. + /// + /// Using this function in a const context is deprecated in favor of + /// [`as_char_ptr_in_const_context`] in preparation for replacing `CSt= r` with `core::ffi::CStr` + /// which does not have this method. #[inline] pub const fn as_char_ptr(&self) -> *const c_char { - self.0.as_ptr() + as_char_ptr_in_const_context(self) } =20 /// Convert the string to a byte slice without the trailing `NUL` byte. #[inline] - pub fn as_bytes(&self) -> &[u8] { + pub fn to_bytes(&self) -> &[u8] { &self.0[..self.len()] } =20 + /// Convert the string to a byte slice without the trailing `NUL` byte. + /// + /// This function is deprecated in favor of [`Self::to_bytes`] in prep= aration for replacing + /// `CStr` with `core::ffi::CStr` which does not have this method. + #[inline] + pub fn as_bytes(&self) -> &[u8] { + self.to_bytes() + } + /// Convert the string to a byte slice containing the trailing `NUL` b= yte. #[inline] - pub const fn as_bytes_with_nul(&self) -> &[u8] { + pub const fn to_bytes_with_nul(&self) -> &[u8] { &self.0 } =20 + /// Convert the string to a byte slice containing the trailing `NUL` b= yte. + /// + /// This function is deprecated in favor of [`Self::to_bytes_with_nul`= ] in preparation for + /// replacing `CStr` with `core::ffi::CStr` which does not have this m= ethod. + #[inline] + pub const fn as_bytes_with_nul(&self) -> &[u8] { + self.to_bytes_with_nul() + } + /// Yields a [`&str`] slice if the [`CStr`] contains valid UTF-8. /// /// If the contents of the [`CStr`] are valid UTF-8 data, this --=20 2.50.0 From nobody Tue Oct 7 21:18:30 2025 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 788EC250C18; Fri, 4 Jul 2025 20:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660173; cv=none; b=FB6aWvh6jf/HXb9dbu05zCGwyXm4q/y2LC4Y9M+dK9Gzwagm8QI+ezn+SnsjWKKdFi5UdtoeG9x3ISAZ6QXC5jPKBVO6piLkH//KGtHC/j0G0ySdPMlZYy7TNiY4iBe8lCFg1t5UJ55fQUnBRt8/gmVSbDOFEes00d1QLWs5H7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751660173; c=relaxed/simple; bh=Gr5Y82FzFOHSFgE4bAXR4LJsBEIiMIFEwMxnG28mI/k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=li0hTmDI3KIDe5+LB/sHwShHOwyudr/fk+JPDHk7kwwZRwne12xDoGtgZHwgLLxZ8AjibCja5Y/1hiY9LDvXZb+pB9AVnBb2q0/jaPYrN5pJGj19yZVHvCeEe8E2ZScjo55EjgeXdA3Ep4+2agNLokPbFIXSzER8nS4EZmUJHhs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RXMPVN3x; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RXMPVN3x" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4a9741b513eso26494171cf.1; Fri, 04 Jul 2025 13:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751660170; x=1752264970; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rFX61eKYEcol9kAG3M8tjgApkaTg0NmTOXaZhr2OWW4=; b=RXMPVN3xaoPBDMTmD64gjDH0KCHAUONIaBXUsEvMch0qQMuG/RHb4IkpFJuEwQiVFx 8On1ffWGxFXAtpfuRXhyu5Tx9Yml05vYGW0W0YFYx6kCkxgOFVAwD2CqJdAN+X7wGrHN LgVgehPWw6Ol6l0xyLNwReLWaUs0uawlEw8v4G5baaa5n6KYAtYzEeUokQl6mQwOnpab xHSWOnNMW1AseKJ3/QC+KhBFgXsXf3b47WFw9DXCAvwRKCzEVOTv1geMsovoGnVfmdL+ BImJMEYn5fBWh7ThMX99Fek3AkVbHwM5bOBirrW+IhlxUf+kZjOgV6PlCTPo0AJ4pjCl i2CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751660170; x=1752264970; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rFX61eKYEcol9kAG3M8tjgApkaTg0NmTOXaZhr2OWW4=; b=slxTWIddRkH7SB253vupn6I32AIaMLFYw1WMm67FUAzgKQZq+fsLvyTQWc0jNiOb2Q 35Ae8mEh9LZ/51TKEwMz5YY7R9BTzZGJwhmGfmevxL8cub3No55J7QMfPJz0ULIn5DAN NBgaYnGy1Yt/Ujqr2LGRDvfJJGZPd0CLzok/2gJ+k/wbQf/fp86S8MvApgT8H7qiFfq1 7fhL2XmmvN+CirhnMvB6kioQsb0FtkfBLG8rvkF6rvLlR2o4eg1yxz8Q5O9gSTf0bZFH eWOYaGlF4TDLzXY620RCnwyCHR3LHDIhulO4WbDaAi5bOhRsAM3tGeODaOTjaFGzmv36 Qxvw== X-Forwarded-Encrypted: i=1; AJvYcCXOcYAuz5kpuFVArUVabfZFT1iuCadv5Um1P60MIbCvSyPx0OcMlu4TvoLy7cjZmuCBR8mkxwq0i+TiSyEloJ8=@vger.kernel.org, AJvYcCXfSN8nbgcOiJHUgZDc46FOoMyL98+YiV7o3kAdoQkhlg1a43g+cMdDYVXQZCUwzvlGTDCFGkXFFARB7fM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1S1S5zD9KuEihdsTTHBX+ZX5PVbl1YyofCZMgjJDwOij9sIW/ IilhIUeEaMwYa57+87BylPm37PnwBMEsRZAyK3R4ym9Hv+Ylqjwqc+YUVsSzQwydLNhVWg== X-Gm-Gg: ASbGncu2BbHEgquAnOBEHWbq3T8uSEaChuc0GaT3s9SgpwKZSLevSVv/qCUtyrHSmRa BWmKYpKDc/gs2vpQyzZHjTW/aDV9371DqS/P3FP5xiCkwZsbPmqfq/FWMdQ37hYOQL6OGpK2wfD J1H41WKxqqjbOZ8XZhoKd5n50KKNrtQiyD/QOmIlB4lwEsdu5TpQOzS4bTDGOFphdKadKHSub/s +X29vaR3PEiwMBq6KjBD/u8PdPxj7SIoqiKf23hp9vKgql804qnC1Z1BRTGrTxqAvns124SORTN /NLr4m1WZUb4MZYr8CMWq64zE00cxPeOJrDmooPWmknOGRZaIXXYYbsCnQ6Zcc3av3DgngmT4wy BrfEbndw= X-Google-Smtp-Source: AGHT+IHCClMp3qYZhSGQu4QEJmyo61DmZpj8XQCRl0CIpaNBHANR9wOTxi6Qz7IzHn6a7YD26jNiWw== X-Received: by 2002:ac8:7f8f:0:b0:494:59b0:7347 with SMTP id d75a77b69052e-4a9a69f76cfmr2280131cf.37.1751660170283; Fri, 04 Jul 2025 13:16:10 -0700 (PDT) Received: from 156.1.168.192.in-addr.arpa ([2600:4041:5c29:e400:94f3:d2bb:5ace:77a1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a9949e5221sm19772941cf.2.2025.07.04.13.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 13:16:09 -0700 (PDT) From: Tamir Duberstein Date: Fri, 04 Jul 2025 16:14:57 -0400 Subject: [PATCH 6/6] rust: use `core::ffi::CStr` method names Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-core-cstr-prepare-v1-6-a91524037783@gmail.com> References: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> In-Reply-To: <20250704-core-cstr-prepare-v1-0-a91524037783@gmail.com> To: "Rafael J. Wysocki" , Viresh Kumar , Danilo Krummrich , David Airlie , Simona Vetter , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openssh-sha256; t=1751660161; l=4785; i=tamird@gmail.com; h=from:subject:message-id; bh=Gr5Y82FzFOHSFgE4bAXR4LJsBEIiMIFEwMxnG28mI/k=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtYz36g7iDMSkY5K7Ab51ksGX7hJgs MRt+XVZTrIzMVIAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QLas4zvU0lCc78yU+Yb9DLjcVMQs5g7e5Va+eCFZgvaWEOcJlCw4GoHKAaftU93fC6280TgpoTe TE2iS8TMjrAY= X-Developer-Key: i=tamird@gmail.com; a=openssh; fpr=SHA256:264rPmnnrb+ERkS7DDS3tuwqcJss/zevJRzoylqMsbc Prepare for `core::ffi::CStr` taking the place of `kernel::str::CStr` by avoiding methods that only exist on the latter. Also avoid `Deref for CStr` as that impl doesn't exist on `core::ffi::CStr`. Link: https://github.com/Rust-for-Linux/linux/issues/1075 Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/error.rs | 2 +- rust/kernel/str.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index ffa8efd2d547..e29a5d76300e 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -188,7 +188,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Resul= t { Some(name) =3D> f .debug_tuple( // SAFETY: These strings are ASCII-only. - unsafe { core::str::from_utf8_unchecked(name) }, + unsafe { core::str::from_utf8_unchecked(name.to_bytes(= )) }, ) .finish(), } diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index cbb357fc0111..6c892550c0ba 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -57,11 +57,11 @@ impl fmt::Display for BStr { /// # use kernel::{prelude::fmt, b_str, str::{BStr, CString}}; /// let ascii =3D b_str!("Hello, BStr!"); /// let s =3D CString::try_from_fmt(fmt!("{ascii}"))?; - /// assert_eq!(s.as_bytes(), "Hello, BStr!".as_bytes()); + /// assert_eq!(s.to_bytes(), "Hello, BStr!".as_bytes()); /// /// let non_ascii =3D b_str!("=F0=9F=A6=80"); /// let s =3D CString::try_from_fmt(fmt!("{non_ascii}"))?; - /// assert_eq!(s.as_bytes(), "\\xf0\\x9f\\xa6\\x80".as_bytes()); + /// assert_eq!(s.to_bytes(), "\\xf0\\x9f\\xa6\\x80".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -89,11 +89,11 @@ impl fmt::Debug for BStr { /// // Embedded double quotes are escaped. /// let ascii =3D b_str!("Hello, \"BStr\"!"); /// let s =3D CString::try_from_fmt(fmt!("{ascii:?}"))?; - /// assert_eq!(s.as_bytes(), "\"Hello, \\\"BStr\\\"!\"".as_bytes()); + /// assert_eq!(s.to_bytes(), "\"Hello, \\\"BStr\\\"!\"".as_bytes()); /// /// let non_ascii =3D b_str!("=F0=9F=98=BA"); /// let s =3D CString::try_from_fmt(fmt!("{non_ascii:?}"))?; - /// assert_eq!(s.as_bytes(), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes()); + /// assert_eq!(s.to_bytes(), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -465,15 +465,15 @@ impl fmt::Display for CStr { /// # use kernel::str::CString; /// let penguin =3D c_str!("=F0=9F=90=A7"); /// let s =3D CString::try_from_fmt(fmt!("{penguin}"))?; - /// assert_eq!(s.as_bytes_with_nul(), "\\xf0\\x9f\\x90\\xa7\0".as_byte= s()); + /// assert_eq!(s.to_bytes_with_nul(), "\\xf0\\x9f\\x90\\xa7\0".as_byte= s()); /// /// let ascii =3D c_str!("so \"cool\""); /// let s =3D CString::try_from_fmt(fmt!("{ascii}"))?; - /// assert_eq!(s.as_bytes_with_nul(), "so \"cool\"\0".as_bytes()); + /// assert_eq!(s.to_bytes_with_nul(), "so \"cool\"\0".as_bytes()); /// # Ok::<(), kernel::error::Error>(()) /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for &c in self.as_bytes() { + for &c in self.to_bytes() { if (0x20..0x7f).contains(&c) { // Printable character. f.write_char(c as char)?; @@ -874,11 +874,11 @@ fn write_str(&mut self, s: &str) -> fmt::Result { /// use kernel::{str::CString, prelude::fmt}; /// /// let s =3D CString::try_from_fmt(fmt!("{}{}{}", "abc", 10, 20))?; -/// assert_eq!(s.as_bytes_with_nul(), "abc1020\0".as_bytes()); +/// assert_eq!(s.to_bytes_with_nul(), "abc1020\0".as_bytes()); /// /// let tmp =3D "testing"; /// let s =3D CString::try_from_fmt(fmt!("{tmp}{}", 123))?; -/// assert_eq!(s.as_bytes_with_nul(), "testing123\0".as_bytes()); +/// assert_eq!(s.to_bytes_with_nul(), "testing123\0".as_bytes()); /// /// // This fails because it has an embedded `NUL` byte. /// let s =3D CString::try_from_fmt(fmt!("a\0b{}", 123)); @@ -948,7 +948,7 @@ impl<'a> TryFrom<&'a CStr> for CString { fn try_from(cstr: &'a CStr) -> Result { let mut buf =3D KVec::new(); =20 - buf.extend_from_slice(cstr.as_bytes_with_nul(), GFP_KERNEL)?; + buf.extend_from_slice(cstr.to_bytes_with_nul(), GFP_KERNEL)?; =20 // INVARIANT: The `CStr` and `CString` types have the same invaria= nts for // the string data, and we copied it over without changes. --=20 2.50.0