[PATCH v2 17/19] rust: sync: replace `kernel::c_str!` with C-Strings

Tamir Duberstein
2025-09-25T13:56:02Z

drivers/block/rnull.rs | 2 +-
rust/kernel/sync.rs | 5 ++---
rust/kernel/sync/completion.rs | 2 +-
rust/kernel/workqueue.rs | 8 ++++----
4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs
index 6366da12c5a5..9aa79b862b63 100644
--- a/drivers/block/rnull.rs
+++ b/drivers/block/rnull.rs
@@ -55,7 +55,7 @@ fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
})();

try_pin_init!(Self {
- _disk <- new_mutex!(disk?, "nullb:disk"),
+ _disk <- new_mutex!(disk?, c"nullb:disk"),
})
}
}
diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index 00f9b558a3ad..672411058a92 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -44,7 +44,6 @@ impl LockClassKey {
///
/// # Examples
/// ```
- /// # use kernel::c_str;
/// # use kernel::alloc::KBox;
/// # use kernel::types::ForeignOwnable;
/// # use kernel::sync::{LockClassKey, SpinLock};
@@ -56,7 +55,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) }
@@ -115,6 +114,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)?;
///
diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs
index b9343d5bc00f..261b827235ae 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.0