]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: helpers: Generify the definitions of rust_helper_*_cmpxchg*
authorBoqun Feng <boqun.feng@gmail.com>
Tue, 3 Mar 2026 20:16:53 +0000 (12:16 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Sun, 8 Mar 2026 10:06:48 +0000 (11:06 +0100)
To support atomic pointers, more cmpxchg helpers will be introduced,
hence define macros to generate these helpers to ease the introduction
of the future helpers.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260117122243.24404-4-boqun.feng@gmail.com
Link: https://patch.msgid.link/20260303201701.12204-6-boqun@kernel.org
rust/helpers/atomic_ext.c

index c5f665bbe785ff4d6f317411ccfae2c1d177d8ac..240218e2e7083cf8346ec4143d41b918c9211cf6 100644 (file)
@@ -67,42 +67,18 @@ GEN_XCHG_HELPERS(i16, s16)
  * The architectures that currently support Rust (x86_64, armv7,
  * arm64, riscv, and loongarch) satisfy these requirements.
  */
-__rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new)
-{
-       return try_cmpxchg(ptr, old, new);
-}
-
-__rust_helper bool rust_helper_atomic_i16_try_cmpxchg(s16 *ptr, s16 *old, s16 new)
-{
-       return try_cmpxchg(ptr, old, new);
-}
-
-__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_acquire(s8 *ptr, s8 *old, s8 new)
-{
-       return try_cmpxchg_acquire(ptr, old, new);
-}
-
-__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_acquire(s16 *ptr, s16 *old, s16 new)
-{
-       return try_cmpxchg_acquire(ptr, old, new);
-}
-
-__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_release(s8 *ptr, s8 *old, s8 new)
-{
-       return try_cmpxchg_release(ptr, old, new);
-}
-
-__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_release(s16 *ptr, s16 *old, s16 new)
-{
-       return try_cmpxchg_release(ptr, old, new);
+#define GEN_TRY_CMPXCHG_HELPER(tname, type, suffix)                            \
+__rust_helper bool                                                             \
+rust_helper_atomic_##tname##_try_cmpxchg##suffix(type *ptr, type *old, type new)\
+{                                                                              \
+       return try_cmpxchg##suffix(ptr, old, new);                              \
 }
 
-__rust_helper bool rust_helper_atomic_i8_try_cmpxchg_relaxed(s8 *ptr, s8 *old, s8 new)
-{
-       return try_cmpxchg_relaxed(ptr, old, new);
-}
+#define GEN_TRY_CMPXCHG_HELPERS(tname, type)                                   \
+       GEN_TRY_CMPXCHG_HELPER(tname, type, )                                   \
+       GEN_TRY_CMPXCHG_HELPER(tname, type, _acquire)                           \
+       GEN_TRY_CMPXCHG_HELPER(tname, type, _release)                           \
+       GEN_TRY_CMPXCHG_HELPER(tname, type, _relaxed)                           \
 
-__rust_helper bool rust_helper_atomic_i16_try_cmpxchg_relaxed(s16 *ptr, s16 *old, s16 new)
-{
-       return try_cmpxchg_relaxed(ptr, old, new);
-}
+GEN_TRY_CMPXCHG_HELPERS(i8, s8)
+GEN_TRY_CMPXCHG_HELPERS(i16, s16)