Skip to contentSkip to conversation

tools: Upgrade atomic_set() to use WRITE_ONCE()

PATCH New Chih-En Lin 1 participant 1 message Jul 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Upgrade atomic_set() to use WRITE_ONCE()

Since the atomic operation in the tools directory is from the kernel source [1]. And from the commit [2], atomic_set() is at least WRITE_ONCE() in the kernel source. atomic_{read,set}() should be symmetry with {READ, WRITE}_ONCE() [3]. To be synchronous with the source, atomic_set() should use WRITE_ONCE() rather than plain access.

[1] commit da6d8567512d ("tools include: Add basic atomic.h implementation from the kernel sources")
[2] commit 62e8a3258bda ("atomic, arch: Audit atomic_{read,set}()")
[3] commit 6aa7de059173 ("locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()")

---
 tools/arch/x86/include/asm/atomic.h    | 2 +-
 tools/include/asm-generic/atomic-gcc.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/arch/x86/include/asm/atomic.h +1 -1
index 1f5e26aae9fc..4dcf4e9baecc 100644
@@ -37,7 +37,7 @@ static inline int atomic_read(const atomic_t *v)
  */
 static inline void atomic_set(atomic_t *v, int i)
 {
-	v->counter = i;
+	WRITE_ONCE(v->counter, i);
 }
 
 /**
tools/include/asm-generic/atomic-gcc.h +1 -1
index 4c1966f7c77a..df84af8012e6 100644
@@ -34,7 +34,7 @@ static inline int atomic_read(const atomic_t *v)
  */
 static inline void atomic_set(atomic_t *v, int i)
 {
-        v->counter = i;
+	WRITE_ONCE(v->counter, i);
 }
 
 /**
Signature · 1 line
2.25.1