Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: kunit: replace `kernel::c_str!` with C-Strings

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>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://patch.msgid.link/20251222-cstr-kunit-v1-1-39d999672f35@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Tamir Duberstein and committed by
Miguel Ojeda
6c37b684 32d61c51

+11 -14
+4 -7
rust/kernel/kunit.rs
··· 9 9 use crate::fmt; 10 10 use crate::prelude::*; 11 11 12 - #[cfg(CONFIG_PRINTK)] 13 - use crate::c_str; 14 - 15 12 /// Prints a KUnit error-level message. 16 13 /// 17 14 /// Public but hidden since it should only be used from KUnit generated code. ··· 19 22 #[cfg(CONFIG_PRINTK)] 20 23 unsafe { 21 24 bindings::_printk( 22 - c_str!("\x013%pA").as_char_ptr(), 25 + c"\x013%pA".as_char_ptr(), 23 26 core::ptr::from_ref(&args).cast::<c_void>(), 24 27 ); 25 28 } ··· 35 38 #[cfg(CONFIG_PRINTK)] 36 39 unsafe { 37 40 bindings::_printk( 38 - c_str!("\x016%pA").as_char_ptr(), 41 + c"\x016%pA".as_char_ptr(), 39 42 core::ptr::from_ref(&args).cast::<c_void>(), 40 43 ); 41 44 } ··· 57 60 break 'out; 58 61 } 59 62 60 - static FILE: &'static $crate::str::CStr = $crate::c_str!($file); 63 + static FILE: &'static $crate::str::CStr = $file; 61 64 static LINE: i32 = ::core::line!() as i32 - $diff; 62 65 static CONDITION: &'static $crate::str::CStr = $crate::c_str!(stringify!($condition)); 63 66 ··· 250 253 /// } 251 254 /// 252 255 /// static mut KUNIT_TEST_CASES: [kernel::bindings::kunit_case; 2] = [ 253 - /// kernel::kunit::kunit_case(kernel::c_str!("name"), test_fn), 256 + /// kernel::kunit::kunit_case(c"name", test_fn), 254 257 /// kernel::kunit::kunit_case_null(), 255 258 /// ]; 256 259 /// kernel::kunit_unsafe_test_suite!(suite_name, KUNIT_TEST_CASES);
+5 -5
rust/macros/kunit.rs
··· 102 102 // unsafe extern "C" fn kunit_rust_wrapper_bar(_test: *mut ::kernel::bindings::kunit) { bar(); } 103 103 // 104 104 // static mut TEST_CASES: [::kernel::bindings::kunit_case; 3] = [ 105 - // ::kernel::kunit::kunit_case(::kernel::c_str!("foo"), kunit_rust_wrapper_foo), 106 - // ::kernel::kunit::kunit_case(::kernel::c_str!("bar"), kunit_rust_wrapper_bar), 105 + // ::kernel::kunit::kunit_case(c"foo", kunit_rust_wrapper_foo), 106 + // ::kernel::kunit::kunit_case(c"bar", kunit_rust_wrapper_bar), 107 107 // ::kernel::kunit::kunit_case_null(), 108 108 // ]; 109 109 // ··· 133 133 writeln!(kunit_macros, "{kunit_wrapper}").unwrap(); 134 134 writeln!( 135 135 test_cases, 136 - " ::kernel::kunit::kunit_case(::kernel::c_str!(\"{test}\"), {kunit_wrapper_fn_name})," 136 + " ::kernel::kunit::kunit_case(c\"{test}\", {kunit_wrapper_fn_name})," 137 137 ) 138 138 .unwrap(); 139 139 writeln!( ··· 143 143 #[allow(unused)] 144 144 macro_rules! assert {{ 145 145 ($cond:expr $(,)?) => {{{{ 146 - kernel::kunit_assert!("{test}", "{path}", 0, $cond); 146 + kernel::kunit_assert!("{test}", c"{path}", 0, $cond); 147 147 }}}} 148 148 }} 149 149 ··· 151 151 #[allow(unused)] 152 152 macro_rules! assert_eq {{ 153 153 ($left:expr, $right:expr $(,)?) => {{{{ 154 - kernel::kunit_assert_eq!("{test}", "{path}", 0, $left, $right); 154 + kernel::kunit_assert_eq!("{test}", c"{path}", 0, $left, $right); 155 155 }}}} 156 156 }} 157 157 "#
+2 -2
scripts/rustdoc_test_gen.rs
··· 174 174 macro_rules! assert {{ 175 175 ($cond:expr $(,)?) => {{{{ 176 176 ::kernel::kunit_assert!( 177 - "{kunit_name}", "{real_path}", __DOCTEST_ANCHOR - {line}, $cond 177 + "{kunit_name}", c"{real_path}", __DOCTEST_ANCHOR - {line}, $cond 178 178 ); 179 179 }}}} 180 180 }} ··· 184 184 macro_rules! assert_eq {{ 185 185 ($left:expr, $right:expr $(,)?) => {{{{ 186 186 ::kernel::kunit_assert_eq!( 187 - "{kunit_name}", "{real_path}", __DOCTEST_ANCHOR - {line}, $left, $right 187 + "{kunit_name}", c"{real_path}", __DOCTEST_ANCHOR - {line}, $left, $right 188 188 ); 189 189 }}}} 190 190 }}