summaryrefslogtreecommitdiff
path: root/rust/kernel/sync/lock.rs
diff options
context:
space:
mode:
authorDaniel Almeida <daniel.almeida@collabora.com>2025-09-19 11:12:39 +0200
committerPeter Zijlstra <peterz@infradead.org>2025-10-21 12:31:55 +0200
commitda123f0ee40f0e5a3791bbaf58a1db1744c59f72 (patch)
treeb64402f19c9b6f1083dbf36277c28475d895cb87 /rust/kernel/sync/lock.rs
parentc14ecb555c3ee80eeb030a4e46d00e679537f03a (diff)
rust: lock: guard: Add T: Unpin bound to DerefMut
A core property of pinned types is not handing a mutable reference to the inner data in safe code, as this trivially allows that data to be moved. Enforce this condition by adding a bound on lock::Guard's DerefMut implementation, so that it's only implemented for pinning-agnostic types. Suggested-by: Benno Lossin <lossin@kernel.org> Suggested-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://github.com/Rust-for-Linux/linux/issues/1181
Diffstat (limited to 'rust/kernel/sync/lock.rs')
-rw-r--r--rust/kernel/sync/lock.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index 27202beef90c..b482f34bf0ce 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -251,7 +251,10 @@ impl<T: ?Sized, B: Backend> core::ops::Deref for Guard<'_, T, B> {
}
}
-impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> {
+impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B>
+where
+ T: Unpin,
+{
fn deref_mut(&mut self) -> &mut Self::Target {
// SAFETY: The caller owns the lock, so it is safe to deref the protected data.
unsafe { &mut *self.lock.data.get() }