rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings
@ 2025-11-13 22:58 Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 1/6] rust: firmware: " Tamir Duberstein
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

This intentionally includes only those changes that can be taken through
the Rust tree. I will send separate patches after rc1 for the remaining
changes.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v3:
- Include all patches that can be taken through the rust tree.
- Split "sync" patch into "sync" and "workqueue". Kept the tags on both.
- Link to v2: https://lore.kernel.org/r/20250925-core-cstr-cstrings-v2-0-78e0aaace1cd@gmail.com

Changes in v2:
- Rebase.
- Add two patches to address new code.
- Drop incorrectly applied Acked-by tags from Danilo.
- Link to v1: https://lore.kernel.org/r/20250710-core-cstr-cstrings-v1-0-027420ea799e@gmail.com

---
Tamir Duberstein (6):
      rust: firmware: replace `kernel::c_str!` with C-Strings
      rust: net: replace `kernel::c_str!` with C-Strings
      rust: str: replace `kernel::c_str!` with C-Strings
      rust: sync: replace `kernel::c_str!` with C-Strings
      rust: workqueue: replace `kernel::c_str!` with C-Strings
      rust: macros: replace `kernel::c_str!` with C-Strings

 rust/kernel/firmware.rs        |  6 ++---
 rust/kernel/net/phy.rs         |  6 ++---
 rust/kernel/str.rs             | 57 +++++++++++++++++++++---------------------
 rust/kernel/sync.rs            |  5 ++--
 rust/kernel/sync/completion.rs |  2 +-
 rust/kernel/workqueue.rs       |  8 +++---
 rust/macros/module.rs          |  2 +-
 7 files changed, 41 insertions(+), 45 deletions(-)
---
base-commit: 5935461b458463ee51aac8d95c25d7a5e1de8c4d
change-id: 20250710-core-cstr-cstrings-1faaa632f0fd

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


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

* [PATCH v3 1/6] rust: firmware: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 2/6] rust: net: " Tamir Duberstein
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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/firmware.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
index 376e7e77453f..71168d8004e2 100644
--- a/rust/kernel/firmware.rs
+++ b/rust/kernel/firmware.rs
@@ -51,13 +51,13 @@ fn request_nowarn() -> Self {
 /// # Examples
 ///
 /// ```no_run
-/// # use kernel::{c_str, device::Device, firmware::Firmware};
+/// # use kernel::{device::Device, firmware::Firmware};
 ///
 /// # fn no_run() -> Result<(), Error> {
 /// # // SAFETY: *NOT* safe, just for the example to get an `ARef<Device>` instance
 /// # let dev = unsafe { Device::get_device(core::ptr::null_mut()) };
 ///
-/// let fw = Firmware::request(c_str!("path/to/firmware.bin"), &dev)?;
+/// let fw = Firmware::request(c"path/to/firmware.bin", &dev)?;
 /// let blob = fw.data();
 ///
 /// # Ok(())
@@ -204,7 +204,7 @@ macro_rules! module_firmware {
     ($($builder:tt)*) => {
         const _: () = {
             const __MODULE_FIRMWARE_PREFIX: &'static $crate::str::CStr = if cfg!(MODULE) {
-                $crate::c_str!("")
+                c""
             } else {
                 <LocalModule as $crate::ModuleMetadata>::NAME
             };

-- 
2.51.2


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

* [PATCH v3 2/6] rust: net: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 1/6] rust: firmware: " Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-16 22:54   ` Miguel Ojeda
  2025-11-13 22:58 ` [PATCH v3 3/6] rust: str: " Tamir Duberstein
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/net/phy.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index bf6272d87a7b..3ca99db5cccf 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -777,7 +777,6 @@ const fn as_int(&self) -> u32 {
 ///
 /// ```
 /// # mod module_phy_driver_sample {
-/// use kernel::c_str;
 /// use kernel::net::phy::{self, DeviceId};
 /// use kernel::prelude::*;
 ///
@@ -796,7 +795,7 @@ const fn as_int(&self) -> u32 {
 ///
 /// #[vtable]
 /// impl phy::Driver for PhySample {
-///     const NAME: &'static CStr = c_str!("PhySample");
+///     const NAME: &'static CStr = c"PhySample";
 ///     const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
 /// }
 /// # }
@@ -805,7 +804,6 @@ const fn as_int(&self) -> u32 {
 /// This expands to the following code:
 ///
 /// ```ignore
-/// use kernel::c_str;
 /// use kernel::net::phy::{self, DeviceId};
 /// use kernel::prelude::*;
 ///
@@ -825,7 +823,7 @@ const fn as_int(&self) -> u32 {
 ///
 /// #[vtable]
 /// impl phy::Driver for PhySample {
-///     const NAME: &'static CStr = c_str!("PhySample");
+///     const NAME: &'static CStr = c"PhySample";
 ///     const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
 /// }
 ///

-- 
2.51.2


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

* [PATCH v3 3/6] rust: str: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 1/6] rust: firmware: " Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 2/6] rust: net: " Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 4/6] rust: sync: " Tamir Duberstein
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/str.rs | 57 +++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 7593d758fbb7..4d3f46885300 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -277,15 +277,14 @@ impl fmt::Display for CStr {
     /// Formats printable ASCII characters, escaping the rest.
     ///
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::prelude::fmt;
     /// # use kernel::str::CStr;
     /// # use kernel::str::CString;
-    /// let penguin = c_str!("🐧");
+    /// let penguin = c"🐧";
     /// let s = CString::try_from_fmt(fmt!("{penguin}"))?;
     /// assert_eq!(s.to_bytes_with_nul(), "\\xf0\\x9f\\x90\\xa7\0".as_bytes());
     ///
-    /// let ascii = c_str!("so \"cool\"");
+    /// let ascii = c"so \"cool\"";
     /// let s = CString::try_from_fmt(fmt!("{ascii}"))?;
     /// assert_eq!(s.to_bytes_with_nul(), "so \"cool\"\0".as_bytes());
     /// # Ok::<(), kernel::error::Error>(())
@@ -727,40 +726,40 @@ unsafe fn kstrtobool_raw(string: *const u8) -> Result<bool> {
 /// # use kernel::{c_str, str::kstrtobool};
 ///
 /// // Lowercase
-/// assert_eq!(kstrtobool(c_str!("true")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("tr")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("t")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("twrong")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("false")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("f")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("yes")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("no")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("on")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("off")), Ok(false));
+/// assert_eq!(kstrtobool(c"true"), Ok(true));
+/// assert_eq!(kstrtobool(c"tr"), Ok(true));
+/// assert_eq!(kstrtobool(c"t"), Ok(true));
+/// assert_eq!(kstrtobool(c"twrong"), Ok(true));
+/// assert_eq!(kstrtobool(c"false"), Ok(false));
+/// assert_eq!(kstrtobool(c"f"), Ok(false));
+/// assert_eq!(kstrtobool(c"yes"), Ok(true));
+/// assert_eq!(kstrtobool(c"no"), Ok(false));
+/// assert_eq!(kstrtobool(c"on"), Ok(true));
+/// assert_eq!(kstrtobool(c"off"), Ok(false));
 ///
 /// // Camel case
-/// assert_eq!(kstrtobool(c_str!("True")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("False")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("Yes")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("No")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("On")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("Off")), Ok(false));
+/// assert_eq!(kstrtobool(c"True"), Ok(true));
+/// assert_eq!(kstrtobool(c"False"), Ok(false));
+/// assert_eq!(kstrtobool(c"Yes"), Ok(true));
+/// assert_eq!(kstrtobool(c"No"), Ok(false));
+/// assert_eq!(kstrtobool(c"On"), Ok(true));
+/// assert_eq!(kstrtobool(c"Off"), Ok(false));
 ///
 /// // All caps
-/// assert_eq!(kstrtobool(c_str!("TRUE")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("FALSE")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("YES")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("NO")), Ok(false));
-/// assert_eq!(kstrtobool(c_str!("ON")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("OFF")), Ok(false));
+/// assert_eq!(kstrtobool(c"TRUE"), Ok(true));
+/// assert_eq!(kstrtobool(c"FALSE"), Ok(false));
+/// assert_eq!(kstrtobool(c"YES"), Ok(true));
+/// assert_eq!(kstrtobool(c"NO"), Ok(false));
+/// assert_eq!(kstrtobool(c"ON"), Ok(true));
+/// assert_eq!(kstrtobool(c"OFF"), Ok(false));
 ///
 /// // Numeric
-/// assert_eq!(kstrtobool(c_str!("1")), Ok(true));
-/// assert_eq!(kstrtobool(c_str!("0")), Ok(false));
+/// assert_eq!(kstrtobool(c"1"), Ok(true));
+/// assert_eq!(kstrtobool(c"0"), Ok(false));
 ///
 /// // Invalid input
-/// assert_eq!(kstrtobool(c_str!("invalid")), Err(EINVAL));
-/// assert_eq!(kstrtobool(c_str!("2")), Err(EINVAL));
+/// assert_eq!(kstrtobool(c"invalid"), Err(EINVAL));
+/// assert_eq!(kstrtobool(c"2"), Err(EINVAL));
 /// ```
 pub fn kstrtobool(string: &CStr) -> Result<bool> {
     // SAFETY:

-- 
2.51.2


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

* [PATCH v3 4/6] rust: sync: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (2 preceding siblings ...)
  2025-11-13 22:58 ` [PATCH v3 3/6] rust: str: " Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-16 23:09   ` Miguel Ojeda
  2025-11-13 22:58 ` [PATCH v3 5/6] rust: workqueue: " Tamir Duberstein
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/sync.rs            | 5 ++---
 rust/kernel/sync/completion.rs | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index cf5b638a097d..4e503036e123 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -48,7 +48,6 @@ impl LockClassKey {
     ///
     /// # Examples
     /// ```
-    /// # use kernel::c_str;
     /// # use kernel::alloc::KBox;
     /// # use kernel::types::ForeignOwnable;
     /// # use kernel::sync::{LockClassKey, SpinLock};
@@ -60,7 +59,7 @@ impl LockClassKey {
     /// {
     ///     stack_pin_init!(let num: SpinLock<u32> = SpinLock::new(
     ///         0,
-    ///         c_str!("my_spinlock"),
+    ///         c"my_spinlock",
     ///         // SAFETY: `key_ptr` is returned by the above `into_foreign()`, whose
     ///         // `from_foreign()` has not yet been called.
     ///         unsafe { <Pin<KBox<LockClassKey>> as ForeignOwnable>::borrow(key_ptr) }
@@ -119,6 +118,6 @@ macro_rules! optional_name {
         $crate::c_str!(::core::concat!(::core::file!(), ":", ::core::line!()))
     };
     ($name:literal) => {
-        $crate::c_str!($name)
+        $name
     };
 }
diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
index c50012a940a3..97d39c248793 100644
--- a/rust/kernel/sync/completion.rs
+++ b/rust/kernel/sync/completion.rs
@@ -34,7 +34,7 @@
 /// impl MyTask {
 ///     fn new() -> Result<Arc<Self>> {
 ///         let this = Arc::pin_init(pin_init!(MyTask {
-///             work <- new_work!("MyTask::work"),
+///             work <- new_work!(c"MyTask::work"),
 ///             done <- Completion::new(),
 ///         }), GFP_KERNEL)?;
 ///

-- 
2.51.2


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

* [PATCH v3 5/6] rust: workqueue: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (3 preceding siblings ...)
  2025-11-13 22:58 ` [PATCH v3 4/6] rust: sync: " Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-13 22:58 ` [PATCH v3 6/6] rust: macros: " Tamir Duberstein
  2025-11-17  7:25 ` [PATCH v3 0/6] rust: " Miguel Ojeda
  6 siblings, 0 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/workqueue.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs
index 706e833e9702..6dd47095455f 100644
--- a/rust/kernel/workqueue.rs
+++ b/rust/kernel/workqueue.rs
@@ -51,7 +51,7 @@
 //!     fn new(value: i32) -> Result<Arc<Self>> {
 //!         Arc::pin_init(pin_init!(MyStruct {
 //!             value,
-//!             work <- new_work!("MyStruct::work"),
+//!             work <- new_work!(c"MyStruct::work"),
 //!         }), GFP_KERNEL)
 //!     }
 //! }
@@ -98,8 +98,8 @@
 //!         Arc::pin_init(pin_init!(MyStruct {
 //!             value_1,
 //!             value_2,
-//!             work_1 <- new_work!("MyStruct::work_1"),
-//!             work_2 <- new_work!("MyStruct::work_2"),
+//!             work_1 <- new_work!(c"MyStruct::work_1"),
+//!             work_2 <- new_work!(c"MyStruct::work_2"),
 //!         }), GFP_KERNEL)
 //!     }
 //! }
@@ -337,7 +337,7 @@ pub fn try_spawn<T: 'static + Send + FnOnce()>(
         func: T,
     ) -> Result<(), AllocError> {
         let init = pin_init!(ClosureWork {
-            work <- new_work!("Queue::try_spawn"),
+            work <- new_work!(c"Queue::try_spawn"),
             func: Some(func),
         });
 

-- 
2.51.2


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

* [PATCH v3 6/6] rust: macros: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (4 preceding siblings ...)
  2025-11-13 22:58 ` [PATCH v3 5/6] rust: workqueue: " Tamir Duberstein
@ 2025-11-13 22:58 ` Tamir Duberstein
  2025-11-17  7:25 ` [PATCH v3 0/6] rust: " Miguel Ojeda
  6 siblings, 0 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-13 22:58 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori
  Cc: linux-kernel, rust-for-linux, netdev, Tamir Duberstein,
	Greg Kroah-Hartman

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>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/macros/module.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 5ee54a00c0b6..8cef6cc958b5 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -228,7 +228,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
             type LocalModule = {type_};
 
             impl ::kernel::ModuleMetadata for {type_} {{
-                const NAME: &'static ::kernel::str::CStr = ::kernel::c_str!(\"{name}\");
+                const NAME: &'static ::kernel::str::CStr = c\"{name}\";
             }}
 
             // Double nested modules, since then nobody can access the public items inside.

-- 
2.51.2


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

* Re: [PATCH v3 2/6] rust: net: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 ` [PATCH v3 2/6] rust: net: " Tamir Duberstein
@ 2025-11-16 22:54   ` Miguel Ojeda
  0 siblings, 0 replies; 13+ messages in thread
From: Miguel Ojeda @ 2025-11-16 22:54 UTC (permalink / raw)
  To: Tamir Duberstein, FUJITA Tomonori, Trevor Gross
  Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, linux-kernel,
	rust-for-linux, netdev, Tamir Duberstein, Greg Kroah-Hartman

On Thu, Nov 13, 2025 at 11:58 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> 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>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

Tomo, do you want me to pick this up?

Thanks!

Cheers,
Miguel

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

* Re: [PATCH v3 4/6] rust: sync: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 ` [PATCH v3 4/6] rust: sync: " Tamir Duberstein
@ 2025-11-16 23:09   ` Miguel Ojeda
  2025-11-16 23:52     ` Miguel Ojeda
  0 siblings, 1 reply; 13+ messages in thread
From: Miguel Ojeda @ 2025-11-16 23:09 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori, linux-kernel, rust-for-linux, netdev,
	Tamir Duberstein, Greg Kroah-Hartman

On Thu, Nov 13, 2025 at 11:58 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> @@ -119,6 +118,6 @@ macro_rules! optional_name {
>          $crate::c_str!(::core::concat!(::core::file!(), ":", ::core::line!()))
>      };
>      ($name:literal) => {
> -        $crate::c_str!($name)
> +        $name
>      };
>  }

This requires the next commit plus it needs callers of `new_spinlock!`
in Binder to be fixed at the same time.

Cheers,
Miguel

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

* Re: [PATCH v3 4/6] rust: sync: replace `kernel::c_str!` with C-Strings
  2025-11-16 23:09   ` Miguel Ojeda
@ 2025-11-16 23:52     ` Miguel Ojeda
  2025-11-17 14:49       ` Alice Ryhl
  0 siblings, 1 reply; 13+ messages in thread
From: Miguel Ojeda @ 2025-11-16 23:52 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori, linux-kernel, rust-for-linux, netdev,
	Tamir Duberstein, Greg Kroah-Hartman

On Mon, Nov 17, 2025 at 12:09 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> This requires the next commit plus it needs callers of `new_spinlock!`
> in Binder to be fixed at the same time.

Actually, do we even want callers to have to specify `c`?

For instance, in the `module!` macro we originally had `b`, and
removed it for simplicity of callers:

    b13c9880f909 ("rust: macros: take string literals in `module!`")

Cheers,
Miguel

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

* Re: [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings
  2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
                   ` (5 preceding siblings ...)
  2025-11-13 22:58 ` [PATCH v3 6/6] rust: macros: " Tamir Duberstein
@ 2025-11-17  7:25 ` Miguel Ojeda
  6 siblings, 0 replies; 13+ messages in thread
From: Miguel Ojeda @ 2025-11-17  7:25 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	FUJITA Tomonori, linux-kernel, rust-for-linux, netdev,
	Tamir Duberstein, Greg Kroah-Hartman

On Thu, Nov 13, 2025 at 11:58 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
>       rust: firmware: replace `kernel::c_str!` with C-Strings
>       rust: str: replace `kernel::c_str!` with C-Strings
>       rust: macros: replace `kernel::c_str!` with C-Strings

Applied (these three only) to `rust-next` -- thanks everyone!

    [ Removed unused `c_str` import in doctest. - Miguel ]

Given how many transformations there were, perhaps the Reviewed-by's
should have been reset at some point, but given they are simple
patches and you carried them and nobody complained, I kept them.

Cheers,
Miguel

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

* Re: [PATCH v3 4/6] rust: sync: replace `kernel::c_str!` with C-Strings
  2025-11-16 23:52     ` Miguel Ojeda
@ 2025-11-17 14:49       ` Alice Ryhl
  2025-11-17 17:11         ` Tamir Duberstein
  0 siblings, 1 reply; 13+ messages in thread
From: Alice Ryhl @ 2025-11-17 14:49 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Tamir Duberstein, Luis Chamberlain, Russ Weight, Danilo Krummrich,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, FUJITA Tomonori, linux-kernel, rust-for-linux,
	netdev, Tamir Duberstein, Greg Kroah-Hartman

On Mon, Nov 17, 2025 at 12:52:22AM +0100, Miguel Ojeda wrote:
> On Mon, Nov 17, 2025 at 12:09 AM Miguel Ojeda
> <miguel.ojeda.sandonis@gmail.com> wrote:
> >
> > This requires the next commit plus it needs callers of `new_spinlock!`
> > in Binder to be fixed at the same time.
> 
> Actually, do we even want callers to have to specify `c`?
> 
> For instance, in the `module!` macro we originally had `b`, and
> removed it for simplicity of callers:
> 
>     b13c9880f909 ("rust: macros: take string literals in `module!`")

Yeah I think ideally the new_spinlock! macro invokes c_str! on the
provided string literal to avoid users of the macro from needing the
c prefix.

Alice

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

* Re: [PATCH v3 4/6] rust: sync: replace `kernel::c_str!` with C-Strings
  2025-11-17 14:49       ` Alice Ryhl
@ 2025-11-17 17:11         ` Tamir Duberstein
  0 siblings, 0 replies; 13+ messages in thread
From: Tamir Duberstein @ 2025-11-17 17:11 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Luis Chamberlain, Russ Weight, Danilo Krummrich,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, FUJITA Tomonori, linux-kernel, rust-for-linux,
	netdev, Greg Kroah-Hartman

On Mon, Nov 17, 2025 at 9:49 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> On Mon, Nov 17, 2025 at 12:52:22AM +0100, Miguel Ojeda wrote:
> > On Mon, Nov 17, 2025 at 12:09 AM Miguel Ojeda
> > <miguel.ojeda.sandonis@gmail.com> wrote:
> > >
> > > This requires the next commit plus it needs callers of `new_spinlock!`
> > > in Binder to be fixed at the same time.
> >
> > Actually, do we even want callers to have to specify `c`?
> >
> > For instance, in the `module!` macro we originally had `b`, and
> > removed it for simplicity of callers:
> >
> >     b13c9880f909 ("rust: macros: take string literals in `module!`")
>
> Yeah I think ideally the new_spinlock! macro invokes c_str! on the
> provided string literal to avoid users of the macro from needing the
> c prefix.
>
> Alice

Makes sense and done in v4 (which contains only a small portion of
this patch and no others).

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

end of thread, other threads:[~2025-11-17 17:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13 22:58 [PATCH v3 0/6] rust: replace `kernel::c_str!` with C-Strings Tamir Duberstein
2025-11-13 22:58 ` [PATCH v3 1/6] rust: firmware: " Tamir Duberstein
2025-11-13 22:58 ` [PATCH v3 2/6] rust: net: " Tamir Duberstein
2025-11-16 22:54   ` Miguel Ojeda
2025-11-13 22:58 ` [PATCH v3 3/6] rust: str: " Tamir Duberstein
2025-11-13 22:58 ` [PATCH v3 4/6] rust: sync: " Tamir Duberstein
2025-11-16 23:09   ` Miguel Ojeda
2025-11-16 23:52     ` Miguel Ojeda
2025-11-17 14:49       ` Alice Ryhl
2025-11-17 17:11         ` Tamir Duberstein
2025-11-13 22:58 ` [PATCH v3 5/6] rust: workqueue: " Tamir Duberstein
2025-11-13 22:58 ` [PATCH v3 6/6] rust: macros: " Tamir Duberstein
2025-11-17  7:25 ` [PATCH v3 0/6] rust: " Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).