* [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device @ 2026-01-20 14:02 Ryan Foster 2026-01-20 14:49 ` Gary Guo 0 siblings, 1 reply; 6+ messages in thread From: Ryan Foster @ 2026-01-20 14:02 UTC (permalink / raw) To: rust-for-linux, linux-kernel Cc: ojeda, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, gregkh, rafael, dakr, linux-fsdevel, Ryan Foster C-String literals were added in Rust 1.77. Replace instances of `kernel::c_str!` with C-String literals where possible. This patch updates seq_file and device modules to use the native C-string literal syntax (c"...") instead of the kernel::c_str! macro. Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> --- rust/kernel/device.rs | 5 +---- rust/kernel/seq_file.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index 71b200df0f40..1c3d1d962d15 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -12,9 +12,6 @@ }; use core::{any::TypeId, marker::PhantomData, ptr}; -#[cfg(CONFIG_PRINTK)] -use crate::c_str; - pub mod property; // Assert that we can `read()` / `write()` a `TypeId` instance from / into `struct driver_type`. @@ -462,7 +459,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/seq_file.rs b/rust/kernel/seq_file.rs index 855e533813a6..518265558d66 100644 --- a/rust/kernel/seq_file.rs +++ b/rust/kernel/seq_file.rs @@ -4,7 +4,7 @@ //! //! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h) -use crate::{bindings, c_str, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; +use crate::{bindings, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; /// A utility for generating the contents of a seq file. #[repr(transparent)] @@ -36,7 +36,7 @@ pub fn call_printf(&self, args: fmt::Arguments<'_>) { unsafe { bindings::seq_printf( self.inner.get(), - c_str!("%pA").as_char_ptr(), + c"%pA".as_char_ptr(), core::ptr::from_ref(&args).cast::<crate::ffi::c_void>(), ); } -- 2.52.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device 2026-01-20 14:02 [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device Ryan Foster @ 2026-01-20 14:49 ` Gary Guo 2026-01-20 14:59 ` Ryan Foster 2026-01-20 15:00 ` ryan foster 0 siblings, 2 replies; 6+ messages in thread From: Gary Guo @ 2026-01-20 14:49 UTC (permalink / raw) To: Ryan Foster, rust-for-linux, linux-kernel Cc: ojeda, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, gregkh, rafael, dakr, linux-fsdevel On Tue Jan 20, 2026 at 2:02 PM GMT, Ryan Foster wrote: > C-String literals were added in Rust 1.77. Replace instances of > `kernel::c_str!` with C-String literals where possible. > > This patch updates seq_file and device modules to use the native > C-string literal syntax (c"...") instead of the kernel::c_str! macro. > > Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> > --- > rust/kernel/device.rs | 5 +---- > rust/kernel/seq_file.rs | 4 ++-- > 2 files changed, 3 insertions(+), 6 deletions(-) > > diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs > index 71b200df0f40..1c3d1d962d15 100644 > --- a/rust/kernel/device.rs > +++ b/rust/kernel/device.rs > @@ -12,9 +12,6 @@ > }; > use core::{any::TypeId, marker::PhantomData, ptr}; > > -#[cfg(CONFIG_PRINTK)] > -use crate::c_str; > - > pub mod property; > > // Assert that we can `read()` / `write()` a `TypeId` instance from / into `struct driver_type`. > @@ -462,7 +459,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/seq_file.rs b/rust/kernel/seq_file.rs > index 855e533813a6..518265558d66 100644 > --- a/rust/kernel/seq_file.rs > +++ b/rust/kernel/seq_file.rs > @@ -4,7 +4,7 @@ > //! > //! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h) > > -use crate::{bindings, c_str, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; > +use crate::{bindings, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; As you're changing the import list, can you also convert it to the new kernel import style? Best, Gary > > /// A utility for generating the contents of a seq file. > #[repr(transparent)] > @@ -36,7 +36,7 @@ pub fn call_printf(&self, args: fmt::Arguments<'_>) { > unsafe { > bindings::seq_printf( > self.inner.get(), > - c_str!("%pA").as_char_ptr(), > + c"%pA".as_char_ptr(), > core::ptr::from_ref(&args).cast::<crate::ffi::c_void>(), > ); > } ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device 2026-01-20 14:49 ` Gary Guo @ 2026-01-20 14:59 ` Ryan Foster 2026-01-20 15:02 ` Gary Guo 2026-01-20 15:00 ` ryan foster 1 sibling, 1 reply; 6+ messages in thread From: Ryan Foster @ 2026-01-20 14:59 UTC (permalink / raw) To: gary Cc: a.hindborg, aliceryhl, bjorn3_gh, boqun.feng, dakr, gregkh, linux-fsdevel, linux-kernel, lossin, ojeda, rafael, rust-for-linux, tmgross, Ryan Foster C-String literals were added in Rust 1.77. Replace instances of `kernel::c_str!` with C-String literals where possible. This patch updates seq_file and device modules to use the native C-string literal syntax (c"...") instead of the kernel::c_str! macro. While at it, convert imports to the kernel vertical import style. Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> --- rust/kernel/device.rs | 19 ++++++++++++------- rust/kernel/seq_file.rs | 12 ++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index 71b200df0f40..a87350c1a67d 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -5,15 +5,20 @@ //! C header: [`include/linux/device.h`](srctree/include/linux/device.h) use crate::{ - bindings, fmt, + bindings, + fmt, prelude::*, sync::aref::ARef, - types::{ForeignOwnable, Opaque}, + types::{ + ForeignOwnable, + Opaque, // + }, // +}; +use core::{ + any::TypeId, + marker::PhantomData, + ptr, // }; -use core::{any::TypeId, marker::PhantomData, ptr}; - -#[cfg(CONFIG_PRINTK)] -use crate::c_str; pub mod property; @@ -462,7 +467,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/seq_file.rs b/rust/kernel/seq_file.rs index 855e533813a6..109ad6670907 100644 --- a/rust/kernel/seq_file.rs +++ b/rust/kernel/seq_file.rs @@ -4,7 +4,15 @@ //! //! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h) -use crate::{bindings, c_str, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; +use crate::{ + bindings, + fmt, + str::CStrExt as _, + types::{ + NotThreadSafe, + Opaque, // + }, // +}; /// A utility for generating the contents of a seq file. #[repr(transparent)] @@ -36,7 +44,7 @@ pub fn call_printf(&self, args: fmt::Arguments<'_>) { unsafe { bindings::seq_printf( self.inner.get(), - c_str!("%pA").as_char_ptr(), + c"%pA".as_char_ptr(), core::ptr::from_ref(&args).cast::<crate::ffi::c_void>(), ); } -- 2.52.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device 2026-01-20 14:59 ` Ryan Foster @ 2026-01-20 15:02 ` Gary Guo 2026-01-20 21:11 ` Tamir Duberstein 0 siblings, 1 reply; 6+ messages in thread From: Gary Guo @ 2026-01-20 15:02 UTC (permalink / raw) To: Ryan Foster, gary Cc: a.hindborg, aliceryhl, bjorn3_gh, boqun.feng, dakr, gregkh, linux-fsdevel, linux-kernel, lossin, ojeda, rafael, rust-for-linux, tmgross On Tue Jan 20, 2026 at 2:59 PM GMT, Ryan Foster wrote: > C-String literals were added in Rust 1.77. Replace instances of > `kernel::c_str!` with C-String literals where possible. > > This patch updates seq_file and device modules to use the native > C-string literal syntax (c"...") instead of the kernel::c_str! macro. > > While at it, convert imports to the kernel vertical import style. > > Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> > --- > rust/kernel/device.rs | 19 ++++++++++++------- > rust/kernel/seq_file.rs | 12 ++++++++++-- > 2 files changed, 22 insertions(+), 9 deletions(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device 2026-01-20 15:02 ` Gary Guo @ 2026-01-20 21:11 ` Tamir Duberstein 0 siblings, 0 replies; 6+ messages in thread From: Tamir Duberstein @ 2026-01-20 21:11 UTC (permalink / raw) To: Gary Guo Cc: Ryan Foster, a.hindborg, aliceryhl, bjorn3_gh, boqun.feng, dakr, gregkh, linux-fsdevel, linux-kernel, lossin, ojeda, rafael, rust-for-linux, tmgross On Tue, Jan 20, 2026 at 10:17 AM Gary Guo <gary@garyguo.net> wrote: > > On Tue Jan 20, 2026 at 2:59 PM GMT, Ryan Foster wrote: > > C-String literals were added in Rust 1.77. Replace instances of > > `kernel::c_str!` with C-String literals where possible. > > > > This patch updates seq_file and device modules to use the native > > C-string literal syntax (c"...") instead of the kernel::c_str! macro. > > > > While at it, convert imports to the kernel vertical import style. > > > > Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> > > Reviewed-by: Gary Guo <gary@garyguo.net> device.rs was done in https://lore.kernel.org/all/20251222-cstr-driver-core-v1-0-1142a177d0fd@gmail.com/ and seq_file.rs is waiting for a maintainer's ack in https://lore.kernel.org/all/20251222-cstr-vfs-v1-1-18e3d327cbd7@gmail.com/. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device 2026-01-20 14:49 ` Gary Guo 2026-01-20 14:59 ` Ryan Foster @ 2026-01-20 15:00 ` ryan foster 1 sibling, 0 replies; 6+ messages in thread From: ryan foster @ 2026-01-20 15:00 UTC (permalink / raw) To: Gary Guo Cc: rust-for-linux, linux-kernel, ojeda, boqun.feng, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, gregkh, rafael, dakr, linux-fsdevel Hi Gary, Thi is now fixed, great catch thanks. Best ,Ryan On Tue, Jan 20, 2026 at 6:50 AM Gary Guo <gary@garyguo.net> wrote: > > On Tue Jan 20, 2026 at 2:02 PM GMT, Ryan Foster wrote: > > C-String literals were added in Rust 1.77. Replace instances of > > `kernel::c_str!` with C-String literals where possible. > > > > This patch updates seq_file and device modules to use the native > > C-string literal syntax (c"...") instead of the kernel::c_str! macro. > > > > Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com> > > --- > > rust/kernel/device.rs | 5 +---- > > rust/kernel/seq_file.rs | 4 ++-- > > 2 files changed, 3 insertions(+), 6 deletions(-) > > > > diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs > > index 71b200df0f40..1c3d1d962d15 100644 > > --- a/rust/kernel/device.rs > > +++ b/rust/kernel/device.rs > > @@ -12,9 +12,6 @@ > > }; > > use core::{any::TypeId, marker::PhantomData, ptr}; > > > > -#[cfg(CONFIG_PRINTK)] > > -use crate::c_str; > > - > > pub mod property; > > > > // Assert that we can `read()` / `write()` a `TypeId` instance from / into `struct driver_type`. > > @@ -462,7 +459,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/seq_file.rs b/rust/kernel/seq_file.rs > > index 855e533813a6..518265558d66 100644 > > --- a/rust/kernel/seq_file.rs > > +++ b/rust/kernel/seq_file.rs > > @@ -4,7 +4,7 @@ > > //! > > //! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h) > > > > -use crate::{bindings, c_str, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; > > +use crate::{bindings, fmt, str::CStrExt as _, types::NotThreadSafe, types::Opaque}; > > As you're changing the import list, can you also convert it to the new kernel > import style? > > Best, > Gary > > > > > /// A utility for generating the contents of a seq file. > > #[repr(transparent)] > > @@ -36,7 +36,7 @@ pub fn call_printf(&self, args: fmt::Arguments<'_>) { > > unsafe { > > bindings::seq_printf( > > self.inner.get(), > > - c_str!("%pA").as_char_ptr(), > > + c"%pA".as_char_ptr(), > > core::ptr::from_ref(&args).cast::<crate::ffi::c_void>(), > > ); > > } > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-01-20 21:12 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-01-20 14:02 [PATCH] rust: replace `kernel::c_str!` with C-Strings in seq_file and device Ryan Foster 2026-01-20 14:49 ` Gary Guo 2026-01-20 14:59 ` Ryan Foster 2026-01-20 15:02 ` Gary Guo 2026-01-20 21:11 ` Tamir Duberstein 2026-01-20 15:00 ` ryan foster
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®