summaryrefslogtreecommitdiff
path: root/rust/kernel/sync/atomic
diff options
context:
space:
mode:
authorAndreas Hindborg <a.hindborg@kernel.org>2026-03-03 12:16:59 -0800
committerPeter Zijlstra <peterz@infradead.org>2026-03-08 11:06:50 +0100
commitc49cf341090b53d2afa4dc7c8007ddeefbb3b37f (patch)
treedc9130f447004a2fdce7dd7a070032ba107a91c2 /rust/kernel/sync/atomic
parente2f9c86f33abb89d3e52436018f58e5fb951cc04 (diff)
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 <a.hindborg@kernel.org> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260220-atomic-sub-v3-1-e63cbed1d2aa@kernel.org Link: https://patch.msgid.link/20260303201701.12204-12-boqun@kernel.org
Diffstat (limited to 'rust/kernel/sync/atomic')
-rw-r--r--rust/kernel/sync/atomic/internal.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs
index e301db4eaf919..b762dbdf6d189 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<Self>, 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()) }
+ }
}
);