From c49cf341090b53d2afa4dc7c8007ddeefbb3b37f Mon Sep 17 00:00:00 2001 From: Andreas Hindborg Date: Tue, 3 Mar 2026 12:16:59 -0800 Subject: rust: sync: atomic: Add fetch_sub() Add `Atomic::fetch_sub()` with implementation and documentation in line with existing `Atomic::fetch_add()` implementation. Signed-off-by: Andreas Hindborg Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Alice Ryhl Link: https://patch.msgid.link/20260220-atomic-sub-v3-1-e63cbed1d2aa@kernel.org Link: https://patch.msgid.link/20260303201701.12204-12-boqun@kernel.org --- rust/kernel/sync/atomic/internal.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'rust/kernel/sync/atomic') diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs index e301db4eaf91..b762dbdf6d18 100644 --- a/rust/kernel/sync/atomic/internal.rs +++ b/rust/kernel/sync/atomic/internal.rs @@ -340,5 +340,10 @@ declare_and_impl_atomic_methods!( // SAFETY: `a.as_ptr()` is valid and properly aligned. unsafe { bindings::#call(v, a.as_ptr().cast()) } } + + fn fetch_sub[acquire, release, relaxed](a: &AtomicRepr, v: Self::Delta) -> Self { + // SAFETY: `a.as_ptr()` guarantees the returned pointer is valid and properly aligned. + unsafe { bindings::#call(v, a.as_ptr().cast()) } + } } ); -- cgit v1.2.3