diff --git a/rust/helpers.c b/rust/helpers.c index 3526129f41c79a..cf4ddd705f222c 100644 --- a/rust/helpers.c +++ b/rust/helpers.c @@ -8,6 +8,7 @@ #include #include #include +#include void rust_helper_BUG(void) { @@ -123,6 +124,12 @@ const char *rust_helper_errname(int err) return errname(err); } +void rust_helper_mutex_lock(struct mutex *lock) +{ + mutex_lock(lock); +} +EXPORT_SYMBOL_GPL(rust_helper_mutex_lock); + /* We use bindgen's --size_t-is-usize option to bind the C size_t type * as the Rust usize type, so we can use it in contexts where Rust * expects a usize like slice (array) indices. usize is defined to be diff --git a/rust/kernel/sync/mutex.rs b/rust/kernel/sync/mutex.rs index 0a4371a7db6c74..74654631c8ce1b 100644 --- a/rust/kernel/sync/mutex.rs +++ b/rust/kernel/sync/mutex.rs @@ -77,19 +77,18 @@ impl NeedsLockClass for Mutex { } } +extern "C" { + fn rust_helper_mutex_lock(mutex: *mut bindings::mutex); +} + impl Lock for Mutex { type Inner = T; - #[cfg(not(CONFIG_DEBUG_LOCK_ALLOC))] fn lock_noguard(&self) { // SAFETY: `mutex` points to valid memory. - unsafe { bindings::mutex_lock(self.mutex.get()) }; - } - - #[cfg(CONFIG_DEBUG_LOCK_ALLOC)] - fn lock_noguard(&self) { - // SAFETY: `mutex` points to valid memory. - unsafe { bindings::mutex_lock_nested(self.mutex.get(), 0) }; + unsafe { + rust_helper_mutex_lock(self.mutex.get()); + } } unsafe fn unlock(&self) {