Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Daniel Almeida and committed by
Peter Zijlstra
da123f0e c14ecb55

+8 -2
+4 -1
rust/kernel/sync/lock.rs
··· 251 251 } 252 252 } 253 253 254 - impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> { 254 + impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> 255 + where 256 + T: Unpin, 257 + { 255 258 fn deref_mut(&mut self) -> &mut Self::Target { 256 259 // SAFETY: The caller owns the lock, so it is safe to deref the protected data. 257 260 unsafe { &mut *self.lock.data.get() }
+4 -1
rust/kernel/sync/lock/global.rs
··· 106 106 } 107 107 } 108 108 109 - impl<B: GlobalLockBackend> core::ops::DerefMut for GlobalGuard<B> { 109 + impl<B: GlobalLockBackend> core::ops::DerefMut for GlobalGuard<B> 110 + where 111 + B::Item: Unpin, 112 + { 110 113 fn deref_mut(&mut self) -> &mut Self::Target { 111 114 &mut self.inner 112 115 }