lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251222-cstr-driver-core-v1-7-1142a177d0fd@gmail.com>
Date: Mon, 22 Dec 2025 13:35:33 +0100
From: Tamir Duberstein <tamird@...nel.org>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
 Dave Ertman <david.m.ertman@...el.com>, Ira Weiny <ira.weiny@...el.com>, 
 Leon Romanovsky <leon@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, 
 Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, 
 Björn Roy Baron <bjorn3_gh@...tonmail.com>, 
 Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>, 
 Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, 
 Danilo Krummrich <dakr@...nel.org>, "Rafael J. Wysocki" <rafael@...nel.org>, 
 Daniel Almeida <daniel.almeida@...labora.com>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Tamir Duberstein <tamird@...il.com>
Subject: [PATCH 7/7] samples: rust: debugfs: replace `kernel::c_str!` with
 C-Strings

From: Tamir Duberstein <tamird@...il.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@...il.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ