From 9720b80b794339e5abe10a1733ee6ae71b19e6fd Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 28 Mar 2021 23:25:19 +0200 Subject: [PATCH 1/3] MAINTAINERS: add Wedson Signed-off-by: Miguel Ojeda --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0958079188c81e..bd5d7731346a60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15550,6 +15550,7 @@ F: drivers/infiniband/ulp/rtrs/ RUST M: Miguel Ojeda M: Alex Gaynor +M: Wedson Almeida Filho L: rust-for-linux@vger.kernel.org S: Maintained W: https://github.com/Rust-for-Linux/linux From 6cb92dc4197357c95891243eab0ce293cd88d8fc Mon Sep 17 00:00:00 2001 From: Wedson Almeida Filho Date: Mon, 29 Mar 2021 12:28:56 +0100 Subject: [PATCH 2/3] Implementers of `FileOperations` need to be `Send` as well. --- rust/kernel/file_operations.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rust/kernel/file_operations.rs b/rust/kernel/file_operations.rs index 24d6f9ed0a41f4..2784298f71b0ea 100644 --- a/rust/kernel/file_operations.rs +++ b/rust/kernel/file_operations.rs @@ -415,8 +415,9 @@ impl IoctlCommand { /// You implement this trait whenever you would create a `struct file_operations`. /// /// File descriptors may be used from multiple threads/processes concurrently, so your type must be -/// [`Sync`]. -pub trait FileOperations: Sync + Sized { +/// [`Sync`]. It must also be [`Send`] because [`FileOperations::release`] will be called from the +/// thread that decrements that associated file's refcount to zero. +pub trait FileOperations: Send + Sync + Sized { /// The methods to use to populate [`struct file_operations`]. const TO_USE: ToUse; From 2ea89dd1c5852e8b857937766474c34bc2c12d59 Mon Sep 17 00:00:00 2001 From: Wedson Almeida Filho Date: Tue, 30 Mar 2021 16:40:28 +0100 Subject: [PATCH 3/3] Warn if the caller doesn't check if a signal is pending. --- drivers/char/rust_example.rs | 4 ++-- rust/kernel/sync/condvar.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/char/rust_example.rs b/drivers/char/rust_example.rs index 8a91713f485a7e..1fa9f065468d87 100644 --- a/drivers/char/rust_example.rs +++ b/drivers/char/rust_example.rs @@ -102,7 +102,7 @@ impl KernelModule for RustExample { let guard = data.lock(); #[allow(clippy::while_immutable_condition)] while *guard != 10 { - cv.wait(&guard); + let _ = cv.wait(&guard); } } cv.notify_one(); @@ -125,7 +125,7 @@ impl KernelModule for RustExample { let guard = data.lock(); #[allow(clippy::while_immutable_condition)] while *guard != 10 { - cv.wait(&guard); + let _ = cv.wait(&guard); } } cv.notify_one(); diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index bb9a34516957c3..131dde9c008b22 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -64,6 +64,7 @@ impl CondVar { /// [`CondVar::notify_all`], or when the thread receives a signal. /// /// Returns whether there is a signal pending. + #[must_use = "wait returns if a signal is pending, so the caller must check the return value"] pub fn wait(&self, guard: &Guard) -> bool { let lock = guard.lock; let mut wait = MaybeUninit::::uninit();