Skip to content

Commit

Permalink
Merge pull request torvalds#357 from TheSven73/rust-for-linux-no-ifdefs2
Browse files Browse the repository at this point in the history
rust/kernel: remove config `#ifdef` in mutex.rs file
  • Loading branch information
ojeda authored Jun 8, 2021
2 parents 66893e3 + a8553d8 commit 7764b8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/highmem.h>
#include <linux/uio.h>
#include <linux/errname.h>
#include <linux/mutex.h>

void rust_helper_BUG(void)
{
Expand Down Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions rust/kernel/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,18 @@ impl<T: ?Sized> NeedsLockClass for Mutex<T> {
}
}

extern "C" {
fn rust_helper_mutex_lock(mutex: *mut bindings::mutex);
}

impl<T: ?Sized> Lock for Mutex<T> {
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) {
Expand Down

0 comments on commit 7764b8c

Please sign in to comment.