Skip to content

Commit 7764b8c

Browse files
authored
Merge pull request #357 from TheSven73/rust-for-linux-no-ifdefs2
rust/kernel: remove config `#ifdef` in mutex.rs file
2 parents 66893e3 + a8553d8 commit 7764b8c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

rust/helpers.c

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/highmem.h>
99
#include <linux/uio.h>
1010
#include <linux/errname.h>
11+
#include <linux/mutex.h>
1112

1213
void rust_helper_BUG(void)
1314
{
@@ -123,6 +124,12 @@ const char *rust_helper_errname(int err)
123124
return errname(err);
124125
}
125126

127+
void rust_helper_mutex_lock(struct mutex *lock)
128+
{
129+
mutex_lock(lock);
130+
}
131+
EXPORT_SYMBOL_GPL(rust_helper_mutex_lock);
132+
126133
/* We use bindgen's --size_t-is-usize option to bind the C size_t type
127134
* as the Rust usize type, so we can use it in contexts where Rust
128135
* expects a usize like slice (array) indices. usize is defined to be

rust/kernel/sync/mutex.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,18 @@ impl<T: ?Sized> NeedsLockClass for Mutex<T> {
7777
}
7878
}
7979

80+
extern "C" {
81+
fn rust_helper_mutex_lock(mutex: *mut bindings::mutex);
82+
}
83+
8084
impl<T: ?Sized> Lock for Mutex<T> {
8185
type Inner = T;
8286

83-
#[cfg(not(CONFIG_DEBUG_LOCK_ALLOC))]
8487
fn lock_noguard(&self) {
8588
// SAFETY: `mutex` points to valid memory.
86-
unsafe { bindings::mutex_lock(self.mutex.get()) };
87-
}
88-
89-
#[cfg(CONFIG_DEBUG_LOCK_ALLOC)]
90-
fn lock_noguard(&self) {
91-
// SAFETY: `mutex` points to valid memory.
92-
unsafe { bindings::mutex_lock_nested(self.mutex.get(), 0) };
89+
unsafe {
90+
rust_helper_mutex_lock(self.mutex.get());
91+
}
9392
}
9493

9594
unsafe fn unlock(&self) {

0 commit comments

Comments
 (0)