]> Git Repo - J-linux.git/commitdiff
jump_label: rust: pass a mut ptr to `static_key_count`
authorAlice Ryhl <[email protected]>
Mon, 18 Nov 2024 20:27:26 +0000 (20:27 +0000)
committerSteven Rostedt (Google) <[email protected]>
Mon, 18 Nov 2024 22:09:28 +0000 (17:09 -0500)
When building the rust_print sample with CONFIG_JUMP_LABEL=n, the Rust
static key support falls back to using static_key_count. This function
accepts a mutable pointer to the `struct static_key`, but the Rust
abstractions are incorrectly passing a const pointer.

This means that builds using CONFIG_JUMP_LABEL=n and SAMPLE_RUST_PRINT=y
fail with the following error message:

error[E0308]: mismatched types
  --> <root>/samples/rust/rust_print_main.rs:87:5
   |
87 | /     kernel::declare_trace! {
88 | |         /// # Safety
89 | |         ///
90 | |         /// Always safe to call.
91 | |         unsafe fn rust_sample_loaded(magic: c_int);
92 | |     }
   | |     ^
   | |     |
   | |_____types differ in mutability
   |       arguments to this function are incorrect
   |
   = note: expected raw pointer `*mut kernel::bindings::static_key`
              found raw pointer `*const kernel::bindings::static_key`
note: function defined here
  --> <root>/rust/bindings/bindings_helpers_generated.rs:33:12
   |
33 |     pub fn static_key_count(key: *mut static_key) -> c_int;
   |            ^^^^^^^^^^^^^^^^

To fix this, insert a pointer cast so that the pointer is mutable.

Link: https://lore.kernel.org/[email protected]
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Fixes: 169484ab6677 ("rust: add arch_static_branch")
Signed-off-by: Alice Ryhl <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
rust/kernel/jump_label.rs

index 2f2df03a3275e1bb44c3ce9f506616c8fbc98a94..b5aff632ecc736837c85c416666e387b10ae9a62 100644 (file)
@@ -26,7 +26,7 @@ macro_rules! static_branch_unlikely {
 
         #[cfg(not(CONFIG_JUMP_LABEL))]
         {
-            $crate::bindings::static_key_count(_key) > 0
+            $crate::bindings::static_key_count(_key.cast_mut()) > 0
         }
 
         #[cfg(CONFIG_JUMP_LABEL)]
This page took 0.046228 seconds and 4 git commands to generate.