From: Tamir Duberstein <tamird@kernel.org>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Dave Ertman" <david.m.ertman@intel.com>,
"Ira Weiny" <ira.weiny@intel.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Tamir Duberstein <tamird@gmail.com>
Subject: [PATCH 7/7] samples: rust: debugfs: replace `kernel::c_str!` with C-Strings
Date: Mon, 22 Dec 2025 13:35:33 +0100 [thread overview]
Message-ID: <20251222-cstr-driver-core-v1-7-1142a177d0fd@gmail.com> (raw)
In-Reply-To: <20251222-cstr-driver-core-v1-0-1142a177d0fd@gmail.com>
From: Tamir Duberstein <tamird@gmail.com>
C-String literals were added in Rust 1.77. Replace instances of
`kernel::c_str!` with C-String literals where possible.
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
samples/rust/rust_debugfs.rs | 17 ++++++++---------
samples/rust/rust_debugfs_scoped.rs | 20 ++++++++------------
2 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
index 025e8f9d12de..2888619443d3 100644
--- a/samples/rust/rust_debugfs.rs
+++ b/samples/rust/rust_debugfs.rs
@@ -32,7 +32,6 @@
//! ```
use core::str::FromStr;
-use kernel::c_str;
use kernel::debugfs::{Dir, File};
use kernel::new_mutex;
use kernel::prelude::*;
@@ -98,7 +97,7 @@ fn from_str(s: &str) -> Result<Self> {
ACPI_TABLE,
MODULE_ACPI_TABLE,
<RustDebugFs as platform::Driver>::IdInfo,
- [(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())]
+ [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
);
impl platform::Driver for RustDebugFs {
@@ -125,34 +124,34 @@ fn probe(
impl RustDebugFs {
fn build_counter(dir: &Dir) -> impl PinInit<File<Atomic<usize>>> + '_ {
- dir.read_write_file(c_str!("counter"), Atomic::<usize>::new(0))
+ dir.read_write_file(c"counter", Atomic::<usize>::new(0))
}
fn build_inner(dir: &Dir) -> impl PinInit<File<Mutex<Inner>>> + '_ {
- dir.read_write_file(c_str!("pair"), new_mutex!(Inner { x: 3, y: 10 }))
+ dir.read_write_file(c"pair", new_mutex!(Inner { x: 3, y: 10 }))
}
fn new(pdev: &platform::Device<Core>) -> impl PinInit<Self, Error> + '_ {
- let debugfs = Dir::new(c_str!("sample_debugfs"));
+ let debugfs = Dir::new(c"sample_debugfs");
let dev = pdev.as_ref();
try_pin_init! {
Self {
_compatible <- debugfs.read_only_file(
- c_str!("compatible"),
+ c"compatible",
dev.fwnode()
.ok_or(ENOENT)?
- .property_read::<CString>(c_str!("compatible"))
+ .property_read::<CString>(c"compatible")
.required_by(dev)?,
),
counter <- Self::build_counter(&debugfs),
inner <- Self::build_inner(&debugfs),
array_blob <- debugfs.read_write_binary_file(
- c_str!("array_blob"),
+ c"array_blob",
new_mutex!([0x62, 0x6c, 0x6f, 0x62]),
),
vector_blob <- debugfs.read_write_binary_file(
- c_str!("vector_blob"),
+ c"vector_blob",
new_mutex!(kernel::kvec!(0x42; SZ_4K)?),
),
_debugfs: debugfs,
diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
index 702a6546d3fb..358c47bae4d0 100644
--- a/samples/rust/rust_debugfs_scoped.rs
+++ b/samples/rust/rust_debugfs_scoped.rs
@@ -11,7 +11,7 @@
use kernel::sizes::*;
use kernel::sync::atomic::Atomic;
use kernel::sync::Mutex;
-use kernel::{c_str, new_mutex, str::CString};
+use kernel::{new_mutex, str::CString};
module! {
type: RustScopedDebugFs,
@@ -80,7 +80,7 @@ fn create_file_write(
};
dir.read_write_file(&name, val);
}
- dir.read_write_binary_file(c_str!("blob"), &dev_data.blob);
+ dir.read_write_binary_file(c"blob", &dev_data.blob);
},
),
GFP_KERNEL,
@@ -119,20 +119,16 @@ struct DeviceData {
}
fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {
- base_dir.scope(
- ModuleData::init(dyn_dirs),
- c_str!("control"),
- |data, dir| {
- dir.write_only_callback_file(c_str!("create"), data, &create_file_write);
- dir.write_only_callback_file(c_str!("remove"), data, &remove_file_write);
- },
- )
+ base_dir.scope(ModuleData::init(dyn_dirs), c"control", |data, dir| {
+ dir.write_only_callback_file(c"create", data, &create_file_write);
+ dir.write_only_callback_file(c"remove", data, &remove_file_write);
+ })
}
impl kernel::Module for RustScopedDebugFs {
fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
- let base_dir = Dir::new(c_str!("rust_scoped_debugfs"));
- let dyn_dirs = base_dir.subdir(c_str!("dynamic"));
+ let base_dir = Dir::new(c"rust_scoped_debugfs");
+ let dyn_dirs = base_dir.subdir(c"dynamic");
Ok(Self {
_data: KBox::pin_init(init_control(&base_dir, dyn_dirs), GFP_KERNEL)?,
})
--
2.52.0
next prev parent reply other threads:[~2025-12-22 12:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
2025-12-22 12:35 ` [PATCH 1/7] rust: auxiliary: " Tamir Duberstein
2025-12-22 12:35 ` [PATCH 2/7] rust: device: " Tamir Duberstein
2025-12-22 12:35 ` [PATCH 3/7] rust: platform: " Tamir Duberstein
2025-12-22 12:35 ` [PATCH 4/7] rust: io: " Tamir Duberstein
2025-12-22 12:35 ` [PATCH 5/7] rust: irq: " Tamir Duberstein
2025-12-22 12:35 ` [PATCH 6/7] rust: debugfs: " Tamir Duberstein
2025-12-22 12:35 ` Tamir Duberstein [this message]
2025-12-22 13:16 ` [PATCH 0/7] driver-core: rust: " Daniel Almeida
2025-12-22 16:46 ` Danilo Krummrich
2025-12-23 7:41 ` Tamir Duberstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251222-cstr-driver-core-v1-7-1142a177d0fd@gmail.com \
--to=tamird@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=ira.weiny@intel.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox