Skip to content

Commit d065cc7

Browse files
dirkbehmeojeda
authored andcommitted
rust: mutex: fix __mutex_init() usage in case of PREEMPT_RT
In case CONFIG_PREEMPT_RT is enabled __mutex_init() becomes a macro instead of an extern function (simplified from include/linux/mutex.h): #ifndef CONFIG_PREEMPT_RT extern void __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key); #else #define __mutex_init(mutex, name, key) \ do { \ rt_mutex_base_init(&(mutex)->rtmutex); \ __mutex_rt_init((mutex), name, key); \ } while (0) #endif The macro isn't resolved by bindgen, then. What results in a build error: error[E0425]: cannot find function `__mutex_init` in crate `bindings` --> rust/kernel/sync/lock/mutex.rs:104:28 | 104 | unsafe { bindings::__mutex_init(ptr, name, key) } | ^^^^^^^^^^^^ help: a function with a similar name exists: `__mutex_rt_init` | ::: rust/bindings/bindings_generated.rs:23722:5 | 23722 | / pub fn __mutex_rt_init( 23723 | | lock: *mut mutex, 23724 | | name: *const core::ffi::c_char, 23725 | | key: *mut lock_class_key, 23726 | | ); | |_____- similarly named function `__mutex_rt_init` defined here Fix this by adding a helper. As explained by Gary Guo in [1] no #ifdef CONFIG_PREEMPT_RT is needed here as rust/bindings/lib.rs prefers externed function to helpers if an externed function exists. Reported-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/rust-for-linux/20240913-shack-estate-b376a65921b1@spud/ Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] Fixes: 6d20d62 ("rust: lock: introduce `Mutex`") Signed-off-by: Dirk Behme <[email protected]> Tested-by: Conor Dooley <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded to include the proper example by Dirk. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 732cd68 commit d065cc7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust/helpers/mutex.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ void rust_helper_mutex_lock(struct mutex *lock)
77
{
88
mutex_lock(lock);
99
}
10+
11+
void rust_helper___mutex_init(struct mutex *mutex, const char *name,
12+
struct lock_class_key *key)
13+
{
14+
__mutex_init(mutex, name, key);
15+
}

0 commit comments

Comments
 (0)