Skip to content

Commit bec2fa2

Browse files
fbqgregkh
authored andcommitted
rust: sync: atomic: Remove bound T: Sync for Atomic::from_ptr()
[ Upstream commit 4a5dc63 ] Originally, `Atomic::from_ptr()` requires `T` being a `Sync` because I thought having the ability to do `from_ptr()` meant multiplle `&Atomic<T>`s shared by different threads, which was identical (or similar) to multiple `&T`s shared by different threads. Hence `T` was required to be `Sync`. However this is not true, since `&Atomic<T>` is not the same at `&T`. Moreover, having this bound makes `Atomic::<*mut T>::from_ptr()` impossible, which is definitely not intended. Therefore remove the `T: Sync` bound. [boqun: Fix title typo spotted by Alice & Gary] Fixes: 29c32c4 ("rust: sync: atomic: Add generic atomics") Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260120115207.55318-2-boqun.feng@gmail.com Link: https://patch.msgid.link/20260303201701.12204-2-boqun@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 90e8cfc commit bec2fa2

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

rust/kernel/sync/atomic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ impl<T: AtomicType> Atomic<T> {
202202
/// // no data race.
203203
/// unsafe { Atomic::from_ptr(foo_a_ptr) }.store(2, Release);
204204
/// ```
205-
pub unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a Self
206-
where
207-
T: Sync,
208-
{
205+
pub unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a Self {
209206
// CAST: `T` and `Atomic<T>` have the same size, alignment and bit validity.
210207
// SAFETY: Per function safety requirement, `ptr` is a valid pointer and the object will
211208
// live long enough. It's safe to return a `&Atomic<T>` because function safety requirement

0 commit comments

Comments
 (0)