locking,arch: Use ACCESS_ONCE() instead of cast to volatile in atomic_read()
authorPranith Kumar <bobby.prani@gmail.com>
Tue, 23 Sep 2014 14:29:50 +0000 (10:29 -0400)
committerIngo Molnar <mingo@kernel.org>
Fri, 3 Oct 2014 04:06:23 +0000 (06:06 +0200)
Use the much more reader friendly ACCESS_ONCE() instead of the cast to volatile.
This is purely a stylistic change.

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
Acked-by: Jesper Nilsson <jesper.nilsson@axis.com>
Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-arch@vger.kernel.org
Link: http://lkml.kernel.org/r/1411482607-20948-1-git-send-email-bobby.prani@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
18 files changed:
arch/alpha/include/asm/atomic.h
arch/arm/include/asm/atomic.h
arch/arm64/include/asm/atomic.h
arch/avr32/include/asm/atomic.h
arch/cris/include/asm/atomic.h
arch/frv/include/asm/atomic.h
arch/ia64/include/asm/atomic.h
arch/m32r/include/asm/atomic.h
arch/m68k/include/asm/atomic.h
arch/mips/include/asm/atomic.h
arch/parisc/include/asm/atomic.h
arch/sh/include/asm/atomic.h
arch/sparc/include/asm/atomic_32.h
arch/sparc/include/asm/atomic_64.h
arch/x86/include/asm/atomic.h
arch/x86/include/asm/atomic64_64.h
arch/xtensa/include/asm/atomic.h
include/asm-generic/atomic.h

index 6fbb53a13049de1b17db495d350a0e03c70324ab..8f8eafbedd7c2970ec1dbd403ec2e3d135079927 100644 (file)
@@ -17,8 +17,8 @@
 #define ATOMIC_INIT(i)         { (i) }
 #define ATOMIC64_INIT(i)       { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
-#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
+#define atomic64_read(v)       ACCESS_ONCE((v)->counter)
 
 #define atomic_set(v,i)                ((v)->counter = (i))
 #define atomic64_set(v,i)      ((v)->counter = (i))
index 832f1cdfcd6aecfc7e85b0ddc7c18027e9b7bfe2..e22c11970b7bd278e5a030a364c2b66ba3572e6f 100644 (file)
@@ -27,7 +27,7 @@
  * strex/ldrex monitor on some implementations. The reason we can use it for
  * atomic_set() is the clrex or dummy strex done on every exception return.
  */
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
+#define atomic_read(v) ACCESS_ONCE((v)->counter)
 #define atomic_set(v,i)        (((v)->counter) = (i))
 
 #if __LINUX_ARM_ARCH__ >= 6
index b83c325e587f1a1c055aa9c957e8b8e5260aa9c8..7047051ded40e3e9c3cc944fe0ce456bb6eaf897 100644 (file)
@@ -35,7 +35,7 @@
  * strex/ldrex monitor on some implementations. The reason we can use it for
  * atomic_set() is the clrex or dummy strex done on every exception return.
  */
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
+#define atomic_read(v) ACCESS_ONCE((v)->counter)
 #define atomic_set(v,i)        (((v)->counter) = (i))
 
 /*
@@ -139,7 +139,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  */
 #define ATOMIC64_INIT(i) { (i) }
 
-#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
+#define atomic64_read(v)       ACCESS_ONCE((v)->counter)
 #define atomic64_set(v,i)      (((v)->counter) = (i))
 
 #define ATOMIC64_OP(op, asm_op)                                                \
index 83e980a4e48392b701c0a9ac545faa25ca590613..2d07ce1c5327cae2f0428714757ecf0163b8605d 100644 (file)
@@ -19,7 +19,7 @@
 
 #define ATOMIC_INIT(i)  { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 #define ATOMIC_OP_RETURN(op, asm_op, asm_con)                          \
index 0033f9dfea2489db87b07ddc8771ebfba78e1c59..279766a70664f6fdc0544397afe302d3f8052761 100644 (file)
@@ -17,7 +17,7 @@
 
 #define ATOMIC_INIT(i)  { (i) }
 
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
+#define atomic_read(v) ACCESS_ONCE((v)->counter)
 #define atomic_set(v,i) (((v)->counter) = (i))
 
 /* These should be written in asm but we do it in C for now. */
index f6c3a16901011b9fc6600a6a5c26ae42b004c2a8..102190a61d65a1fb28f4775309a167355cebcca7 100644 (file)
@@ -31,7 +31,7 @@
  */
 
 #define ATOMIC_INIT(i)         { (i) }
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = (i))
 
 #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
index 42919a831c6c2a76ae9089261f6dd665143e383f..0bf03501fe5ca6af6d63173743ad52164cb099b5 100644 (file)
@@ -21,8 +21,8 @@
 #define ATOMIC_INIT(i)         { (i) }
 #define ATOMIC64_INIT(i)       { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
-#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
+#define atomic64_read(v)       ACCESS_ONCE((v)->counter)
 
 #define atomic_set(v,i)                (((v)->counter) = (i))
 #define atomic64_set(v,i)      (((v)->counter) = (i))
index 3946b2c8d971d312b2e569534dd1c43324ea64ac..31bb74adba082a03bcd121dfa97ac70037a2653d 100644 (file)
@@ -28,7 +28,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
+#define atomic_read(v) ACCESS_ONCE((v)->counter)
 
 /**
  * atomic_set - set atomic variable
index 663d4ba2462c858fb6645909f8583190724d65c4..e85f047fb072e8aa3aff7bc56b9afc3b33ff842d 100644 (file)
@@ -17,7 +17,7 @@
 
 #define ATOMIC_INIT(i) { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 /*
index f3ee721fe61d9f9ed8987ec59b8843ac752496c2..6dd6bfc607e9a6bee5a2beead58741526d23369e 100644 (file)
@@ -29,7 +29,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 
 /*
  * atomic_set - set atomic variable
@@ -306,7 +306,7 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
  * @v: pointer of type atomic64_t
  *
  */
-#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
+#define atomic64_read(v)       ACCESS_ONCE((v)->counter)
 
 /*
  * atomic64_set - set atomic variable
index 219750bb4ae705999ef230652f8b4bf2c5a0466b..226f8ca993f69372016e634e345cf1d3a139cdb5 100644 (file)
@@ -67,7 +67,7 @@ static __inline__ void atomic_set(atomic_t *v, int i)
 
 static __inline__ int atomic_read(const atomic_t *v)
 {
-       return (*(volatile int *)&(v)->counter);
+       return ACCESS_ONCE((v)->counter);
 }
 
 /* exported interface */
@@ -204,7 +204,7 @@ atomic64_set(atomic64_t *v, s64 i)
 static __inline__ s64
 atomic64_read(const atomic64_t *v)
 {
-       return (*(volatile long *)&(v)->counter);
+       return ACCESS_ONCE((v)->counter);
 }
 
 #define atomic64_inc(v)                (atomic64_add(   1,(v)))
index f57b8a6743b30a24f3008623d8d72bf5deecd3f9..05b9f74ce2d544d3f9d7bede26cdc57c04a54e2c 100644 (file)
@@ -14,7 +14,7 @@
 
 #define ATOMIC_INIT(i) { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 #define atomic_set(v,i)                ((v)->counter = (i))
 
 #if defined(CONFIG_GUSA_RB)
index 7b024f02a7cec9d682c451de1808b8b4f2f22680..765c1776ec9fd6e900e8c23f39e55af0bf2b316b 100644 (file)
@@ -26,7 +26,7 @@ int atomic_cmpxchg(atomic_t *, int, int);
 int __atomic_add_unless(atomic_t *, int, int);
 void atomic_set(atomic_t *, int);
 
-#define atomic_read(v)          (*(volatile int *)&(v)->counter)
+#define atomic_read(v)          ACCESS_ONCE((v)->counter)
 
 #define atomic_add(i, v)       ((void)atomic_add_return( (int)(i), (v)))
 #define atomic_sub(i, v)       ((void)atomic_add_return(-(int)(i), (v)))
index 7e4ca1e73cd9649c9bf7e588f88ba21a17e75625..4082749913ce06109a3bd923e0bef4677d0376c9 100644 (file)
@@ -14,8 +14,8 @@
 #define ATOMIC_INIT(i)         { (i) }
 #define ATOMIC64_INIT(i)       { (i) }
 
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
-#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
+#define atomic64_read(v)       ACCESS_ONCE((v)->counter)
 
 #define atomic_set(v, i)       (((v)->counter) = i)
 #define atomic64_set(v, i)     (((v)->counter) = i)
index bf20c817ed34bc0083641ba402cdea6098d6f1fa..5e5cd123fdfbc2b0fe90cabc5d27948d3ded267a 100644 (file)
@@ -24,7 +24,7 @@
  */
 static inline int atomic_read(const atomic_t *v)
 {
-       return (*(volatile int *)&(v)->counter);
+       return ACCESS_ONCE((v)->counter);
 }
 
 /**
index 46e9052bbd28cdea457130607cd5a50ddc5c6204..f8d273e18516dedf885bbafb16224c189913e14f 100644 (file)
@@ -18,7 +18,7 @@
  */
 static inline long atomic64_read(const atomic64_t *v)
 {
-       return (*(volatile long *)&(v)->counter);
+       return ACCESS_ONCE((v)->counter);
 }
 
 /**
index 626676660b80a929ab6b61320b78e4d5f9aa51c9..00b7d46b35b848226cacd90034bc241181d3389c 100644 (file)
@@ -47,7 +47,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic_read(v)         ACCESS_ONCE((v)->counter)
 
 /**
  * atomic_set - set atomic variable
index 56d4d36e15312785c92fdca776f92d912815ed77..1973ad2b13f4dd80c750e4ff5c71d2e1510c4ff8 100644 (file)
@@ -126,7 +126,7 @@ ATOMIC_OP(or, |)
  * Atomically reads the value of @v.
  */
 #ifndef atomic_read
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
+#define atomic_read(v) ACCESS_ONCE((v)->counter)
 #endif
 
 /**