[PATCH 1/2] rust: sync: atomic: Update safety requirements for `AtomicAdd`
From: Ivan Tverdokhleb
Date: Mon Nov 16 2026 - 14:50:33 EST
The `# Safety` comment on `AtomicAdd` contained an unresolved TODO and a
broken sentence ("...to must yield...") without properly defining
`wrapping_add`. Remove the TODO, fix the phrasing, and define it as
wrapping two's-complement addition (`v.wrapping_add(delta)`), which
accurately reflects the behavior of the underlying integer primitives
since `AtomicImpl` itself has no `wrapping_add` method.
Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@xxxxxxxxx>
---
rust/kernel/sync/atomic.rs | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
index 6d27898add42..5f6491fafd34 100644
--- a/rust/kernel/sync/atomic.rs
+++ b/rust/kernel/sync/atomic.rs
@@ -127,10 +127,11 @@ pub unsafe trait AtomicType: Sized + Copy {
///
/// # Safety
///
-// TODO: Properly defines `wrapping_add` in the following comment.
-/// `wrapping_add` any value of type `Self::Repr::Delta` obtained by [`Self::rhs_into_delta()`] to
-/// any value of type `Self::Repr` obtained through transmuting a value of type `Self` to must
-/// yield a value with a bit pattern also valid for `Self`.
+/// Given a value `v` of type `Self::Repr` obtained by transmuting a value of type [`Self`], and
+/// a value `delta` of type `<Self::Repr as AtomicImpl>::Delta` obtained by
+/// [`Self::rhs_into_delta()`], the wrapping two's-complement addition of `delta` to `v` (that is,
+/// `v.wrapping_add(delta)` on primitive integer types) must yield a value with a bit pattern also
+/// valid for [`Self`].
pub unsafe trait AtomicAdd<Rhs = Self>: AtomicType {
/// Converts `Rhs` into the `Delta` type of the atomic implementation.
fn rhs_into_delta(rhs: Rhs) -> <Self::Repr as AtomicImpl>::Delta;
--
2.56.1