rust: sync: atomic: Update safety requirements for `AtomicAdd`
Subsystems (3)
PATCH 1/2 rust: sync: atomic: Update safety requirements for `AtomicAdd`
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 <[email protected]>
--- rust/kernel/sync/atomic.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
rust/kernel/sync/atomic.rs +5 -4
@@ -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 ;
Signature · 1 line
2.56.1
PATCH 2/2 rust: sync: atomic: Fix typo in SAFETY comment for `isize`
The SAFETY comment for the AtomicAdd<isize> impl of isize says the result is a valid usize. Fix it to say isize.
Signed-off-by Ivan Tverdokhleb <[email protected]>
--- rust/kernel/sync/atomic/predefine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/sync/atomic/predefine.rs +1 -1
@@ -106,7 +106,7 @@ unsafe impl super::AtomicType for isize {type Repr =isize_atomic_repr ; } -// SAFETY: The wrapping add result of two `isize_atomic_repr`s is a valid `usize`. +// SAFETY: The wrapping add result of two `isize_atomic_repr`s is a valid `isize`. unsafe impl super ::AtomicAdd <isize >for isize {fn rhs_into_delta (rhs:isize ) ->isize_atomic_repr { rhsas isize_atomic_repr
Signature · 1 line
2.56.1