[tip: locking/core] rust: sync: atomic: Remove bound `T: Sync` for `Atomic::from_ptr()`

From: tip-bot2 for Boqun Feng

Date: Mon Mar 09 2026 - 15:55:43 EST


The following commit has been merged into the locking/core branch of tip:

Commit-ID: 4a5dc632e0b603ec1cbbf87b78de86b4b6359cff
Gitweb: https://git.kernel.org/tip/4a5dc632e0b603ec1cbbf87b78de86b4b6359cff
Author: Boqun Feng <boqun.feng@xxxxxxxxx>
AuthorDate: Tue, 03 Mar 2026 12:16:49 -08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Sun, 08 Mar 2026 11:06:47 +01:00

rust: sync: atomic: Remove bound `T: Sync` for `Atomic::from_ptr()`

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: 29c32c405e53 ("rust: sync: atomic: Add generic atomics")
Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
Link: https://patch.msgid.link/20260120115207.55318-2-boqun.feng@xxxxxxxxx
Link: https://patch.msgid.link/20260303201701.12204-2-boqun@xxxxxxxxxx
---
rust/kernel/sync/atomic.rs | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
index 4aebeac..296b25e 100644
--- a/rust/kernel/sync/atomic.rs
+++ b/rust/kernel/sync/atomic.rs
@@ -204,10 +204,7 @@ impl<T: AtomicType> Atomic<T> {
/// // no data race.
/// unsafe { Atomic::from_ptr(foo_a_ptr) }.store(2, Release);
/// ```
- pub unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a Self
- where
- T: Sync,
- {
+ pub unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a Self {
// CAST: `T` and `Atomic<T>` have the same size, alignment and bit validity.
// SAFETY: Per function safety requirement, `ptr` is a valid pointer and the object will
// live long enough. It's safe to return a `&Atomic<T>` because function safety requirement