public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings
@ 2025-12-22 12:35 Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 1/7] rust: auxiliary: " Tamir Duberstein
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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>
---
Tamir Duberstein (7):
      rust: auxiliary: replace `kernel::c_str!` with C-Strings
      rust: device: replace `kernel::c_str!` with C-Strings
      rust: platform: replace `kernel::c_str!` with C-Strings
      rust: io: replace `kernel::c_str!` with C-Strings
      rust: irq: replace `kernel::c_str!` with C-Strings
      rust: debugfs: replace `kernel::c_str!` with C-Strings
      samples: rust: debugfs: replace `kernel::c_str!` with C-Strings

 rust/kernel/debugfs.rs                | 23 +++++++++--------------
 rust/kernel/device.rs                 |  4 +---
 rust/kernel/device/property.rs        |  6 +++---
 rust/kernel/io/mem.rs                 |  7 +++----
 rust/kernel/irq/request.rs            |  6 ++----
 rust/kernel/platform.rs               |  6 +++---
 samples/rust/rust_debugfs.rs          | 17 ++++++++---------
 samples/rust/rust_debugfs_scoped.rs   | 20 ++++++++------------
 samples/rust/rust_driver_auxiliary.rs |  4 ++--
 samples/rust/rust_driver_faux.rs      |  4 ++--
 samples/rust/rust_driver_platform.rs  | 30 ++++++++++++++----------------
 11 files changed, 55 insertions(+), 72 deletions(-)
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-driver-core-8bf66543f532

Best regards,
--  
Tamir Duberstein <tamird@gmail.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/7] rust: auxiliary: replace `kernel::c_str!` with C-Strings
  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 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 2/7] rust: device: " Tamir Duberstein
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 samples/rust/rust_driver_auxiliary.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 5761ea314f44..1e4fb23cfcb0 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -5,7 +5,7 @@
 //! To make this driver probe, QEMU must be run with `-device pci-testdev`.
 
 use kernel::{
-    auxiliary, c_str,
+    auxiliary,
     device::{Bound, Core},
     devres::Devres,
     driver,
@@ -19,7 +19,7 @@
 use pin_init::PinInit;
 
 const MODULE_NAME: &CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
-const AUXILIARY_NAME: &CStr = c_str!("auxiliary");
+const AUXILIARY_NAME: &CStr = c"auxiliary";
 
 struct AuxiliaryDriver;
 

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/7] rust: device: replace `kernel::c_str!` with C-Strings
  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 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 3/7] rust: platform: " Tamir Duberstein
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/device.rs          | 4 +---
 rust/kernel/device/property.rs | 6 +++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index c79be2e2bfe3..d4edceaf3020 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -12,8 +12,6 @@
 };
 use core::{any::TypeId, marker::PhantomData, ptr};
 
-#[cfg(CONFIG_PRINTK)]
-use crate::c_str;
 use crate::str::CStrExt as _;
 
 pub mod property;
@@ -463,7 +461,7 @@ unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) {
             bindings::_dev_printk(
                 klevel.as_ptr().cast::<crate::ffi::c_char>(),
                 self.as_raw(),
-                c_str!("%pA").as_char_ptr(),
+                c"%pA".as_char_ptr(),
                 core::ptr::from_ref(&msg).cast::<crate::ffi::c_void>(),
             )
         };
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 3a332a8c53a9..3eb3f36d66d0 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -178,11 +178,11 @@ pub fn property_count_elem<T: PropertyInt>(&self, name: &CStr) -> Result<usize>
     /// # Examples
     ///
     /// ```
-    /// # use kernel::{c_str, device::{Device, property::FwNode}, str::CString};
+    /// # use kernel::{device::{Device, property::FwNode}, str::CString};
     /// fn examples(dev: &Device) -> Result {
     ///     let fwnode = dev.fwnode().ok_or(ENOENT)?;
-    ///     let b: u32 = fwnode.property_read(c_str!("some-number")).required_by(dev)?;
-    ///     if let Some(s) = fwnode.property_read::<CString>(c_str!("some-str")).optional() {
+    ///     let b: u32 = fwnode.property_read(c"some-number").required_by(dev)?;
+    ///     if let Some(s) = fwnode.property_read::<CString>(c"some-str").optional() {
     ///         // ...
     ///     }
     ///     Ok(())

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/7] rust: platform: replace `kernel::c_str!` with C-Strings
  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 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 4/7] rust: io: " Tamir Duberstein
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/platform.rs              |  6 +++---
 samples/rust/rust_driver_faux.rs     |  4 ++--
 samples/rust/rust_driver_platform.rs | 30 ++++++++++++++----------------
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index ed889f079cab..abb22a787131 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -137,7 +137,7 @@ macro_rules! module_platform_driver {
 /// # Examples
 ///
 ///```
-/// # use kernel::{acpi, bindings, c_str, device::Core, of, platform};
+/// # use kernel::{acpi, bindings, device::Core, of, platform};
 ///
 /// struct MyDriver;
 ///
@@ -146,7 +146,7 @@ macro_rules! module_platform_driver {
 ///     MODULE_OF_TABLE,
 ///     <MyDriver as platform::Driver>::IdInfo,
 ///     [
-///         (of::DeviceId::new(c_str!("test,device")), ())
+///         (of::DeviceId::new(c"test,device"), ())
 ///     ]
 /// );
 ///
@@ -155,7 +155,7 @@ macro_rules! module_platform_driver {
 ///     MODULE_ACPI_TABLE,
 ///     <MyDriver as platform::Driver>::IdInfo,
 ///     [
-///         (acpi::DeviceId::new(c_str!("LNUXBEEF")), ())
+///         (acpi::DeviceId::new(c"LNUXBEEF"), ())
 ///     ]
 /// );
 ///
diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs
index ecc9fd378cbd..23add3160693 100644
--- a/samples/rust/rust_driver_faux.rs
+++ b/samples/rust/rust_driver_faux.rs
@@ -2,7 +2,7 @@
 
 //! Rust faux device sample.
 
-use kernel::{c_str, faux, prelude::*, Module};
+use kernel::{faux, prelude::*, Module};
 
 module! {
     type: SampleModule,
@@ -20,7 +20,7 @@ impl Module for SampleModule {
     fn init(_module: &'static ThisModule) -> Result<Self> {
         pr_info!("Initialising Rust Faux Device Sample\n");
 
-        let reg = faux::Registration::new(c_str!("rust-faux-sample-device"), None)?;
+        let reg = faux::Registration::new(c"rust-faux-sample-device", None)?;
 
         dev_info!(reg.as_ref(), "Hello from faux device!\n");
 
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 6bf4f0c9633d..a3044d773176 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -63,7 +63,7 @@
 //!
 
 use kernel::{
-    acpi, c_str,
+    acpi,
     device::{
         self,
         property::{FwNodeReferenceArgs, NArgs},
@@ -85,14 +85,14 @@ struct SampleDriver {
     OF_TABLE,
     MODULE_OF_TABLE,
     <SampleDriver as platform::Driver>::IdInfo,
-    [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
+    [(of::DeviceId::new(c"test,rust-device"), Info(42))]
 );
 
 kernel::acpi_device_table!(
     ACPI_TABLE,
     MODULE_ACPI_TABLE,
     <SampleDriver as platform::Driver>::IdInfo,
-    [(acpi::DeviceId::new(c_str!("LNUXBEEF")), Info(0))]
+    [(acpi::DeviceId::new(c"LNUXBEEF"), Info(0))]
 );
 
 impl platform::Driver for SampleDriver {
@@ -124,49 +124,47 @@ impl SampleDriver {
     fn properties_parse(dev: &device::Device) -> Result {
         let fwnode = dev.fwnode().ok_or(ENOENT)?;
 
-        if let Ok(idx) =
-            fwnode.property_match_string(c_str!("compatible"), c_str!("test,rust-device"))
-        {
+        if let Ok(idx) = fwnode.property_match_string(c"compatible", c"test,rust-device") {
             dev_info!(dev, "matched compatible string idx = {}\n", idx);
         }
 
-        let name = c_str!("compatible");
+        let name = c"compatible";
         let prop = fwnode.property_read::<CString>(name).required_by(dev)?;
         dev_info!(dev, "'{name}'='{prop:?}'\n");
 
-        let name = c_str!("test,bool-prop");
-        let prop = fwnode.property_read_bool(c_str!("test,bool-prop"));
+        let name = c"test,bool-prop";
+        let prop = fwnode.property_read_bool(c"test,bool-prop");
         dev_info!(dev, "'{name}'='{prop}'\n");
 
-        if fwnode.property_present(c_str!("test,u32-prop")) {
+        if fwnode.property_present(c"test,u32-prop") {
             dev_info!(dev, "'test,u32-prop' is present\n");
         }
 
-        let name = c_str!("test,u32-optional-prop");
+        let name = c"test,u32-optional-prop";
         let prop = fwnode.property_read::<u32>(name).or(0x12);
         dev_info!(dev, "'{name}'='{prop:#x}' (default = 0x12)\n");
 
         // A missing required property will print an error. Discard the error to
         // prevent properties_parse from failing in that case.
-        let name = c_str!("test,u32-required-prop");
+        let name = c"test,u32-required-prop";
         let _ = fwnode.property_read::<u32>(name).required_by(dev);
 
-        let name = c_str!("test,u32-prop");
+        let name = c"test,u32-prop";
         let prop: u32 = fwnode.property_read(name).required_by(dev)?;
         dev_info!(dev, "'{name}'='{prop:#x}'\n");
 
-        let name = c_str!("test,i16-array");
+        let name = c"test,i16-array";
         let prop: [i16; 4] = fwnode.property_read(name).required_by(dev)?;
         dev_info!(dev, "'{name}'='{prop:?}'\n");
         let len = fwnode.property_count_elem::<u16>(name)?;
         dev_info!(dev, "'{name}' length is {len}\n");
 
-        let name = c_str!("test,i16-array");
+        let name = c"test,i16-array";
         let prop: KVec<i16> = fwnode.property_read_array_vec(name, 4)?.required_by(dev)?;
         dev_info!(dev, "'{name}'='{prop:?}' (KVec)\n");
 
         for child in fwnode.children() {
-            let name = c_str!("test,ref-arg");
+            let name = c"test,ref-arg";
             let nargs = NArgs::N(2);
             let prop: FwNodeReferenceArgs = child.property_get_reference_args(name, nargs, 0)?;
             dev_info!(dev, "'{name}'='{prop:?}'\n");

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/7] rust: io: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (2 preceding siblings ...)
  2025-12-22 12:35 ` [PATCH 3/7] rust: platform: " Tamir Duberstein
@ 2025-12-22 12:35 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 5/7] rust: irq: " Tamir Duberstein
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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>
---
 rust/kernel/io/mem.rs | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/io/mem.rs b/rust/kernel/io/mem.rs
index b03b82cd531b..3b131f6f7733 100644
--- a/rust/kernel/io/mem.rs
+++ b/rust/kernel/io/mem.rs
@@ -5,7 +5,6 @@
 use core::ops::Deref;
 
 use crate::{
-    c_str,
     device::{
         Bound,
         Device, //
@@ -52,7 +51,7 @@ pub(crate) unsafe fn new(device: &'a Device<Bound>, resource: &'a Resource) -> S
     /// illustration purposes.
     ///
     /// ```no_run
-    /// use kernel::{bindings, c_str, platform, of, device::Core};
+    /// use kernel::{bindings, platform, of, device::Core};
     /// struct SampleDriver;
     ///
     /// impl platform::Driver for SampleDriver {
@@ -110,7 +109,7 @@ pub fn iomap_exclusive_sized<const SIZE: usize>(
     /// illustration purposes.
     ///
     /// ```no_run
-    /// use kernel::{bindings, c_str, platform, of, device::Core};
+    /// use kernel::{bindings, platform, of, device::Core};
     /// struct SampleDriver;
     ///
     /// impl platform::Driver for SampleDriver {
@@ -172,7 +171,7 @@ impl<const SIZE: usize> ExclusiveIoMem<SIZE> {
     fn ioremap(resource: &Resource) -> Result<Self> {
         let start = resource.start();
         let size = resource.size();
-        let name = resource.name().unwrap_or(c_str!(""));
+        let name = resource.name().unwrap_or_default();
 
         let region = resource
             .request_region(

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/7] rust: irq: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (3 preceding siblings ...)
  2025-12-22 12:35 ` [PATCH 4/7] rust: io: " Tamir Duberstein
@ 2025-12-22 12:35 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 6/7] rust: debugfs: " Tamir Duberstein
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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>
---
 rust/kernel/irq/request.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/irq/request.rs b/rust/kernel/irq/request.rs
index b150563fdef8..67769800117c 100644
--- a/rust/kernel/irq/request.rs
+++ b/rust/kernel/irq/request.rs
@@ -139,7 +139,6 @@ pub fn irq(&self) -> u32 {
 /// [`Completion::wait_for_completion()`]: kernel::sync::Completion::wait_for_completion
 ///
 /// ```
-/// use kernel::c_str;
 /// use kernel::device::{Bound, Device};
 /// use kernel::irq::{self, Flags, IrqRequest, IrqReturn, Registration};
 /// use kernel::prelude::*;
@@ -167,7 +166,7 @@ pub fn irq(&self) -> u32 {
 ///     handler: impl PinInit<Data, Error>,
 ///     request: IrqRequest<'_>,
 /// ) -> Result<Arc<Registration<Data>>> {
-///     let registration = Registration::new(request, Flags::SHARED, c_str!("my_device"), handler);
+///     let registration = Registration::new(request, Flags::SHARED, c"my_device", handler);
 ///
 ///     let registration = Arc::pin_init(registration, GFP_KERNEL)?;
 ///
@@ -340,7 +339,6 @@ fn handle_threaded(&self, device: &Device<Bound>) -> IrqReturn {
 /// [`Mutex`](kernel::sync::Mutex) to provide interior mutability.
 ///
 /// ```
-/// use kernel::c_str;
 /// use kernel::device::{Bound, Device};
 /// use kernel::irq::{
 ///   self, Flags, IrqRequest, IrqReturn, ThreadedHandler, ThreadedIrqReturn,
@@ -381,7 +379,7 @@ fn handle_threaded(&self, device: &Device<Bound>) -> IrqReturn {
 ///     request: IrqRequest<'_>,
 /// ) -> Result<Arc<ThreadedRegistration<Data>>> {
 ///     let registration =
-///         ThreadedRegistration::new(request, Flags::SHARED, c_str!("my_device"), handler);
+///         ThreadedRegistration::new(request, Flags::SHARED, c"my_device", handler);
 ///
 ///     let registration = Arc::pin_init(registration, GFP_KERNEL)?;
 ///

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/7] rust: debugfs: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (4 preceding siblings ...)
  2025-12-22 12:35 ` [PATCH 5/7] rust: irq: " Tamir Duberstein
@ 2025-12-22 12:35 ` Tamir Duberstein
  2025-12-22 12:35 ` [PATCH 7/7] samples: " Tamir Duberstein
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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>
---
 rust/kernel/debugfs.rs | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs
index facad81e8290..fe7c8c5e3301 100644
--- a/rust/kernel/debugfs.rs
+++ b/rust/kernel/debugfs.rs
@@ -102,9 +102,8 @@ fn create_file<'a, T, E: 'a>(
     /// # Examples
     ///
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::debugfs::Dir;
-    /// let debugfs = Dir::new(c_str!("parent"));
+    /// let debugfs = Dir::new(c"parent");
     /// ```
     pub fn new(name: &CStr) -> Self {
         Dir::create(name, None)
@@ -115,10 +114,9 @@ pub fn new(name: &CStr) -> Self {
     /// # Examples
     ///
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::debugfs::Dir;
-    /// let parent = Dir::new(c_str!("parent"));
-    /// let child = parent.subdir(c_str!("child"));
+    /// let parent = Dir::new(c"parent");
+    /// let child = parent.subdir(c"child");
     /// ```
     pub fn subdir(&self, name: &CStr) -> Self {
         Dir::create(name, Some(self))
@@ -132,11 +130,10 @@ pub fn subdir(&self, name: &CStr) -> Self {
     /// # Examples
     ///
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::debugfs::Dir;
     /// # use kernel::prelude::*;
-    /// # let dir = Dir::new(c_str!("my_debugfs_dir"));
-    /// let file = KBox::pin_init(dir.read_only_file(c_str!("foo"), 200), GFP_KERNEL)?;
+    /// # let dir = Dir::new(c"my_debugfs_dir");
+    /// let file = KBox::pin_init(dir.read_only_file(c"foo", 200), GFP_KERNEL)?;
     /// // "my_debugfs_dir/foo" now contains the number 200.
     /// // The file is removed when `file` is dropped.
     /// # Ok::<(), Error>(())
@@ -161,11 +158,10 @@ pub fn read_only_file<'a, T, E: 'a>(
     /// # Examples
     ///
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::debugfs::Dir;
     /// # use kernel::prelude::*;
-    /// # let dir = Dir::new(c_str!("my_debugfs_dir"));
-    /// let file = KBox::pin_init(dir.read_binary_file(c_str!("foo"), [0x1, 0x2]), GFP_KERNEL)?;
+    /// # let dir = Dir::new(c"my_debugfs_dir");
+    /// let file = KBox::pin_init(dir.read_binary_file(c"foo", [0x1, 0x2]), GFP_KERNEL)?;
     /// # Ok::<(), Error>(())
     /// ```
     pub fn read_binary_file<'a, T, E: 'a>(
@@ -188,12 +184,11 @@ pub fn read_binary_file<'a, T, E: 'a>(
     ///
     /// ```
     /// # use core::sync::atomic::{AtomicU32, Ordering};
-    /// # use kernel::c_str;
     /// # use kernel::debugfs::Dir;
     /// # use kernel::prelude::*;
-    /// # let dir = Dir::new(c_str!("foo"));
+    /// # let dir = Dir::new(c"foo");
     /// let file = KBox::pin_init(
-    ///     dir.read_callback_file(c_str!("bar"),
+    ///     dir.read_callback_file(c"bar",
     ///     AtomicU32::new(3),
     ///     &|val, f| {
     ///       let out = val.load(Ordering::Relaxed);

-- 
2.52.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/7] samples: rust: debugfs: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (5 preceding siblings ...)
  2025-12-22 12:35 ` [PATCH 6/7] rust: debugfs: " Tamir Duberstein
@ 2025-12-22 12:35 ` Tamir Duberstein
  2025-12-22 13:16 ` [PATCH 0/7] driver-core: rust: " Daniel Almeida
  2025-12-22 16:46 ` Danilo Krummrich
  8 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-22 12:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, Daniel Almeida
  Cc: rust-for-linux, linux-kernel, Tamir Duberstein

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (6 preceding siblings ...)
  2025-12-22 12:35 ` [PATCH 7/7] samples: " Tamir Duberstein
@ 2025-12-22 13:16 ` Daniel Almeida
  2025-12-22 16:46 ` Danilo Krummrich
  8 siblings, 0 replies; 11+ messages in thread
From: Daniel Almeida @ 2025-12-22 13:16 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Rafael J. Wysocki, rust-for-linux, linux-kernel,
	Tamir Duberstein



> On 22 Dec 2025, at 09:35, Tamir Duberstein <tamird@kernel.org> wrote:
> 
> 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>
> ---
> Tamir Duberstein (7):
>      rust: auxiliary: replace `kernel::c_str!` with C-Strings
>      rust: device: replace `kernel::c_str!` with C-Strings
>      rust: platform: replace `kernel::c_str!` with C-Strings
>      rust: io: replace `kernel::c_str!` with C-Strings
>      rust: irq: replace `kernel::c_str!` with C-Strings
>      rust: debugfs: replace `kernel::c_str!` with C-Strings
>      samples: rust: debugfs: replace `kernel::c_str!` with C-Strings
> 
> rust/kernel/debugfs.rs                | 23 +++++++++--------------
> rust/kernel/device.rs                 |  4 +---
> rust/kernel/device/property.rs        |  6 +++---
> rust/kernel/io/mem.rs                 |  7 +++----
> rust/kernel/irq/request.rs            |  6 ++----
> rust/kernel/platform.rs               |  6 +++---
> samples/rust/rust_debugfs.rs          | 17 ++++++++---------
> samples/rust/rust_debugfs_scoped.rs   | 20 ++++++++------------
> samples/rust/rust_driver_auxiliary.rs |  4 ++--
> samples/rust/rust_driver_faux.rs      |  4 ++--
> samples/rust/rust_driver_platform.rs  | 30 ++++++++++++++----------------
> 11 files changed, 55 insertions(+), 72 deletions(-)
> ---
> base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
> change-id: 20251222-cstr-driver-core-8bf66543f532
> 
> Best regards,
> --  
> Tamir Duberstein <tamird@gmail.com>
> 

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings
  2025-12-22 12:35 [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (7 preceding siblings ...)
  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
  8 siblings, 1 reply; 11+ messages in thread
From: Danilo Krummrich @ 2025-12-22 16:46 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Rafael J. Wysocki, Daniel Almeida, rust-for-linux, linux-kernel,
	Tamir Duberstein

On Mon Dec 22, 2025 at 1:35 PM CET, Tamir Duberstein wrote:

Applied to driver-core-testing, thanks!

> Tamir Duberstein (7):
>       rust: auxiliary: replace `kernel::c_str!` with C-Strings
>       rust: device: replace `kernel::c_str!` with C-Strings
>       rust: platform: replace `kernel::c_str!` with C-Strings

    [ Use kernel vertical import style; discard unrelated faux changes.
      - Danilo ]

>       rust: io: replace `kernel::c_str!` with C-Strings

    [ Use kernel vertical import style. - Danilo ]

>       rust: irq: replace `kernel::c_str!` with C-Strings
>       rust: debugfs: replace `kernel::c_str!` with C-Strings
>       samples: rust: debugfs: replace `kernel::c_str!` with C-Strings

@Tamir: Can you please send a separate patch for the faux bus?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] driver-core: rust: replace `kernel::c_str!` with C-Strings
  2025-12-22 16:46 ` Danilo Krummrich
@ 2025-12-23  7:41   ` Tamir Duberstein
  0 siblings, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2025-12-23  7:41 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Greg Kroah-Hartman, Dave Ertman, Ira Weiny, Leon Romanovsky,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Rafael J. Wysocki, Daniel Almeida, rust-for-linux, linux-kernel

On Mon, Dec 22, 2025 at 5:46 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Mon Dec 22, 2025 at 1:35 PM CET, Tamir Duberstein wrote:
>
> Applied to driver-core-testing, thanks!
>
> > Tamir Duberstein (7):
> >       rust: auxiliary: replace `kernel::c_str!` with C-Strings
> >       rust: device: replace `kernel::c_str!` with C-Strings
> >       rust: platform: replace `kernel::c_str!` with C-Strings
>
>     [ Use kernel vertical import style; discard unrelated faux changes.
>       - Danilo ]
>
> >       rust: io: replace `kernel::c_str!` with C-Strings
>
>     [ Use kernel vertical import style. - Danilo ]
>
> >       rust: irq: replace `kernel::c_str!` with C-Strings
> >       rust: debugfs: replace `kernel::c_str!` with C-Strings
> >       samples: rust: debugfs: replace `kernel::c_str!` with C-Strings
>
> @Tamir: Can you please send a separate patch for the faux bus?

Sure!

https://lore.kernel.org/all/20251223-cstr-faux-v1-1-ee0c5cf1be4b@gmail.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-12-23  7:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 7/7] samples: " Tamir Duberstein
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox