summaryrefslogtreecommitdiff
path: root/rust/kernel/sync/atomic/predefine.rs
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2025-12-11 20:38:25 +0900
committerBoqun Feng <boqun.feng@gmail.com>2026-01-09 19:01:41 +0800
commitb33796d554f270e19141c0c1fa0a90705a511d2b (patch)
tree44d54997c2cf3a5cc5b9a1eb4957a2093876b1c4 /rust/kernel/sync/atomic/predefine.rs
parentcf4c3bc1445152c1949a4b5fef56d07579fadb1e (diff)
downloadlinux-b33796d554f270e19141c0c1fa0a90705a511d2b.tar.gz
linux-b33796d554f270e19141c0c1fa0a90705a511d2b.zip
rust: sync: atomic: Add i8/i16 load and store support
Add atomic operation support for i8 and i16 types using volatile read/write and smp_load_acquire/smp_store_release helpers. [boqun: Adjust [1] to avoid introduction of impl_atomic_only_load_and_store_ops!() in the middle] Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Link: https://lore.kernel.org/all/20251228120546.1602275-1-fujita.tomonori@gmail.com/ [1] Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251211113826.1299077-4-fujita.tomonori@gmail.com
Diffstat (limited to 'rust/kernel/sync/atomic/predefine.rs')
-rw-r--r--rust/kernel/sync/atomic/predefine.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
index 45a17985cda4..09b357be59b8 100644
--- a/rust/kernel/sync/atomic/predefine.rs
+++ b/rust/kernel/sync/atomic/predefine.rs
@@ -5,6 +5,18 @@
use crate::static_assert;
use core::mem::{align_of, size_of};
+// SAFETY: `i8` has the same size and alignment with itself, and is round-trip transmutable to
+// itself.
+unsafe impl super::AtomicType for i8 {
+ type Repr = i8;
+}
+
+// SAFETY: `i16` has the same size and alignment with itself, and is round-trip transmutable to
+// itself.
+unsafe impl super::AtomicType for i16 {
+ type Repr = i16;
+}
+
// SAFETY: `i32` has the same size and alignment with itself, and is round-trip transmutable to
// itself.
unsafe impl super::AtomicType for i32 {
@@ -118,7 +130,7 @@ mod tests {
#[test]
fn atomic_basic_tests() {
- for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| {
+ for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
assert_eq!(v, x.load(Relaxed));