Skip to contentSkip to conversation

arm64: cmpxchg: update macros to prevent warnings

PATCH New Mark Brown 2 participants 4 messages Dec 3, 2013 – Dec 4, 2013 arm64

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 arm64: cmpxchg: update macros to prevent warnings

From: Mark Hambleton <[email protected]>

Make sure the value we are going to return is referenced in order to avoid warnings from newer GCCs such as:

arch/arm64/include/asm/cmpxchg.h:162:3: warning: value computed is not used [-Wunused-value]
((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
^
net/netfilter/nf_conntrack_core.c:674:2: note: in expansion of macro ?cmpxchg?
cmpxchg(&nf_conntrack_hash_rnd, 0, rand);

[Modified to use the current underlying implementation as current mainline for both cmpxchg() and cmpxchg_local() does -- broonie]

---
 arch/arm64/include/asm/cmpxchg.h | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
arch/arm64/include/asm/cmpxchg.h +17 -11
index 3914c0dcd09c..3f75fdb59447 100644
@@ -158,17 +158,23 @@ 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_local(ptr,o,n)						\
-	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
-				       (unsigned long)(o),		\
-				       (unsigned long)(n),		\
-				       sizeof(*(ptr))))
+#define cmpxchg(ptr, o, n) \
+({ \
+	__typeof__(*(ptr)) __ret; \
+	__ret = (__typeof__(*(ptr))) \
+	__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \
+		sizeof(*(ptr))); \
+	__ret; \
+})
+
+#define cmpxchg_local(ptr, o, n) \
+({ \
+	__typeof__(*(ptr)) __ret; \
+	__ret = (__typeof__(*(ptr))) \
+	__cmpxchg_local((ptr), (unsigned long)(o), \
+		(unsigned long)(n), sizeof(*(ptr))); \
+	__ret; \
+})
 
 #define cmpxchg64(ptr,o,n)		cmpxchg((ptr),(o),(n))
 #define cmpxchg64_local(ptr,o,n)	cmpxchg_local((ptr),(o),(n))
Signature · 1 line
1.8.5
author
#1 lore raw

PATCH 1/1 arm64: cmpxchg: update macros to prevent warnings

Quoted 4 lines · Mark Brown

From: Mark Hambleton <[email protected]>

Make sure the value we are going to return is referenced in order to avoid warnings from newer GCCs such as:

Sorry, I was missing a commit --amend here - resent with the correction
made.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131203/264dc0d8/attachment-0001.sig>

#2 lore raw

PATCH 1/1 arm64: cmpxchg: update macros to prevent warnings

In reply to Mark Brown
Quoted 46 lines · Mark Brown

From: Mark Hambleton <[email protected]>

Make sure the value we are going to return is referenced in order to avoid warnings from newer GCCs such as:

arch/arm64/include/asm/cmpxchg.h:162:3: warning: value computed is not used [-Wunused-value]

  ((__typeof__(*(ptr)))__cmpxchg_mb((ptr),   \
   ^

net/netfilter/nf_conntrack_core.c:674:2: note: in expansion of macro ?cmpxchg?
cmpxchg(&nf_conntrack_hash_rnd, 0, rand);

[Modified to use the current underlying implementation as current mainline for both cmpxchg() and cmpxchg_local() does -- broonie]

---
 arch/arm64/include/asm/cmpxchg.h | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
arch/arm64/include/asm/cmpxchg.h +7 -11
index 3914c0dcd09c..3f75fdb59447 100644
@@ -158,17 +158,23 @@ 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_local(ptr,o,n)						\
-	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
-				       (unsigned long)(o),		\
-				       (unsigned long)(n),		\
-				       sizeof(*(ptr))))
+#define cmpxchg(ptr, o, n) \
+({ \
+	__typeof__(*(ptr)) __ret; \
+	__ret = (__typeof__(*(ptr))) \
+	__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \
+		sizeof(*(ptr))); \
+	__ret; \

arch/arm64/include/asm/cmpxchg.h static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old, · line 177

Quoted 10 lines
arch/arm64/include/asm/cmpxchg.h +10 -0
+})
+
+#define cmpxchg_local(ptr, o, n) \
+({ \
+	__typeof__(*(ptr)) __ret; \
+	__ret = (__typeof__(*(ptr))) \
+	__cmpxchg_local((ptr), (unsigned long)(o), \
+		(unsigned long)(n), sizeof(*(ptr))); \
+	__ret; \
+})

NAK.

This removes barrier semantics from cmpxchg and makes cmpxchg_local refer to something which isn't defined anywhere, so the kernel doesn't even build.

Will

author
#3 lore raw

PATCH 1/1 arm64: cmpxchg: update macros to prevent warnings

Quoted 2 lines · Will Deacon

This removes barrier semantics from cmpxchg and makes cmpxchg_local refer to something which isn't defined anywhere, so the kernel doesn't even build.

Yes, see the followup I sent to this last night (and the fixed version)
- I forgot to do the git add before I did the commit --amend to fix
them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131204/bfd6b67a/attachment-0001.sig>