]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
authorRussell King <rmk+kernel@arm.linux.org.uk>
Tue, 26 May 2015 14:41:41 +0000 (15:41 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Tue, 2 Jun 2015 08:58:20 +0000 (09:58 +0100)
A recent change in kernel/acct.c added a new warning for many
configurations on ARM:

kernel/acct.c: In function 'acct_pin_kill':
arch/arm/include/asm/cmpxchg.h:122:3: warning: value computed is not used [-Wunused-value]

The code is in fact correct, it's just a cmpxchg() call that
intentionally ignores the result, and no other code does that.  The
warning does not show up on x86 because of the way that its cmpxchg()
macro is written. This changes the ARM implementation to use a similar
construct with a compound expression instead of a typecast, which causes
the compiler to not complain about an unused result.

Fix the other macros in this file in a similar way, and place them
just below their function implementations.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/include/asm/cmpxchg.h

index f4d74ab3ec1f4ce0368c2d2749af4ddd8c0d6b52..1692a05d32074c86e8cc3f31440562588e9ab6d2 100644 (file)
@@ -103,8 +103,10 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
        return ret;
 }
 
-#define xchg(ptr,x) \
-       ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
+#define xchg(ptr, x) ({                                                        \
+       (__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr),           \
+                                  sizeof(*(ptr)));                     \
+})
 
 #include <asm-generic/cmpxchg-local.h>
 
@@ -119,14 +121,16 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  * them available.
  */
-#define cmpxchg_local(ptr, o, n)                                              \
-       ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
-                       (unsigned long)(n), sizeof(*(ptr))))
+#define cmpxchg_local(ptr, o, n) ({                                    \
+       (__typeof(*ptr))__cmpxchg_local_generic((ptr),                  \
+                                               (unsigned long)(o),     \
+                                               (unsigned long)(n),     \
+                                               sizeof(*(ptr)));        \
+})
+
 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
 
-#ifndef CONFIG_SMP
 #include <asm-generic/cmpxchg.h>
-#endif
 
 #else  /* min ARCH >= ARMv6 */
 
@@ -202,11 +206,12 @@ static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
        return ret;
 }
 
-#define cmpxchg(ptr,o,n)                                               \
-       ((__typeof__(*(ptr)))__cmpxchg_mb((ptr),                        \
-                                         (unsigned long)(o),           \
-                                         (unsigned long)(n),           \
-                                         sizeof(*(ptr))))
+#define cmpxchg(ptr,o,n) ({                                            \
+       (__typeof__(*(ptr)))__cmpxchg_mb((ptr),                         \
+                                        (unsigned long)(o),            \
+                                        (unsigned long)(n),            \
+                                        sizeof(*(ptr)));               \
+})
 
 static inline unsigned long __cmpxchg_local(volatile void *ptr,
                                            unsigned long old,
@@ -228,6 +233,13 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
        return ret;
 }
 
+#define cmpxchg_local(ptr, o, n) ({                                    \
+       (__typeof(*ptr))__cmpxchg_local((ptr),                          \
+                                       (unsigned long)(o),             \
+                                       (unsigned long)(n),             \
+                                       sizeof(*(ptr)));                \
+})
+
 static inline unsigned long long __cmpxchg64(unsigned long long *ptr,
                                             unsigned long long old,
                                             unsigned long long new)
@@ -253,6 +265,14 @@ static inline unsigned long long __cmpxchg64(unsigned long long *ptr,
        return oldval;
 }
 
+#define cmpxchg64_relaxed(ptr, o, n) ({                                        \
+       (__typeof__(*(ptr)))__cmpxchg64((ptr),                          \
+                                       (unsigned long long)(o),        \
+                                       (unsigned long long)(n));       \
+})
+
+#define cmpxchg64_local(ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n))
+
 static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
                                                unsigned long long old,
                                                unsigned long long new)
@@ -266,23 +286,11 @@ static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
        return ret;
 }
 
-#define cmpxchg_local(ptr,o,n)                                         \
-       ((__typeof__(*(ptr)))__cmpxchg_local((ptr),                     \
-                                      (unsigned long)(o),              \
-                                      (unsigned long)(n),              \
-                                      sizeof(*(ptr))))
-
-#define cmpxchg64(ptr, o, n)                                           \
-       ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr),                      \
-                                       (unsigned long long)(o),        \
-                                       (unsigned long long)(n)))
-
-#define cmpxchg64_relaxed(ptr, o, n)                                   \
-       ((__typeof__(*(ptr)))__cmpxchg64((ptr),                         \
-                                       (unsigned long long)(o),        \
-                                       (unsigned long long)(n)))
-
-#define cmpxchg64_local(ptr, o, n)     cmpxchg64_relaxed((ptr), (o), (n))
+#define cmpxchg64(ptr, o, n) ({                                                \
+       (__typeof__(*(ptr)))__cmpxchg64_mb((ptr),                       \
+                                          (unsigned long long)(o),     \
+                                          (unsigned long long)(n));    \
+})
 
 #endif /* __LINUX_ARM_ARCH__ >= 6 */