Skip to contentSkip to conversation

arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size

PATCH Superseded Pan Xinhui 3 participants 3 messages Feb 23, 2016 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pan Xinhui

author
#0 lore raw

PATCH 1/1 arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size

From: pan xinhui <[email protected]>

__xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg in incorrect way. And no error will be reported until the link stage. To fix such kinds of issues in a easy way, we use BUILD_BUG() here.

---
 arch/powerpc/include/asm/cmpxchg.h | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/cmpxchg.h +5 -14
index d1a8d93..20c0a30 100644
@@ -5,6 +5,7 @@
 #include <linux/compiler.h>
 #include <asm/synch.h>
 #include <asm/asm-compat.h>
+#include <linux/bug.h>
 
 /*
  * Atomic exchange
@@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
 }
 #endif
 
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 {
@@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 		return __xchg_u64(ptr, x);
 #endif
 	}
-	__xchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return x;
 }
 
@@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
 		return __xchg_u64_local(ptr, x);
 #endif
 	}
-	__xchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return x;
 }
 #define xchg(ptr,x)							     \
@@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
 }
 #endif
 
-/* This function doesn't exist, so you'll get a linker error
-   if something tries to do an invalid cmpxchg().  */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
 	  unsigned int size)
@@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
 		return __cmpxchg_u64(ptr, old, new);
 #endif
 	}
-	__cmpxchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return old;
 }
 
@@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
 		return __cmpxchg_u64_local(ptr, old, new);
 #endif
 	}
-	__cmpxchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return old;
 }
 
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw
Quoted 37 lines · Pan Xinhui

From: pan xinhui <[email protected]>

__xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg in incorrect way. And no error will be reported until the link stage. To fix such kinds of issues in a easy way, we use BUILD_BUG() here.

---
 arch/powerpc/include/asm/cmpxchg.h | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/cmpxchg.h +1 -6
index d1a8d93..20c0a30 100644
@@ -5,6 +5,7 @@
 #include <linux/compiler.h>
 #include <asm/synch.h>
 #include <asm/asm-compat.h>
+#include <linux/bug.h>
 
 /*
  * Atomic exchange
@@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
 }
 #endif
 
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 {

arch/powerpc/include/asm/cmpxchg.h __xchg(volatile void *ptr, unsigned long x, unsigned int size) · line 107

Quoted 5 lines
arch/powerpc/include/asm/cmpxchg.h +1 -1
@@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 		return __xchg_u64(ptr, x);
 #endif
 	}
-	__xchg_called_with_bad_pointer();
+	BUILD_BUG();

Maybe we can use BUILD_BUG_ON_MSG(1, "Unsupported size for xchg"), which could provide more information.

With or without this verbosity:

Regards,
Boqun

Quoted 44 lines
arch/powerpc/include/asm/cmpxchg.h +3 -7
 	return x;
 }
 
@@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
 		return __xchg_u64_local(ptr, x);
 #endif
 	}
-	__xchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return x;
 }
 #define xchg(ptr,x)							     \
@@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
 }
 #endif
 
-/* This function doesn't exist, so you'll get a linker error
-   if something tries to do an invalid cmpxchg().  */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
 	  unsigned int size)
@@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
 		return __cmpxchg_u64(ptr, old, new);
 #endif
 	}
-	__cmpxchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return old;
 }
 
@@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
 		return __cmpxchg_u64_local(ptr, old, new);
 #endif
 	}
-	__cmpxchg_called_with_bad_pointer();
+	BUILD_BUG();
 	return old;
 }
 
Signature · 1 line
2.5.0
#2 lore raw
Quoted 21 lines · Boqun Feng
Quoted 20 lines · Pan Xinhui

From: pan xinhui <[email protected]>

arch/powerpc/include/asm/cmpxchg.h +0 -6
index d1a8d93..20c0a30 100644
@@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
 }
 #endif
 
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 {
@@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
Quoted 8 lines

arch/powerpc/include/asm/cmpxchg.h __xchg(volatile void *ptr, unsigned long x, unsigned int size) · line 107

Quoted 5 lines
arch/powerpc/include/asm/cmpxchg.h +1 -1
 		return __xchg_u64(ptr, x);
 #endif
 	}
-	__xchg_called_with_bad_pointer();
+	BUILD_BUG();

Maybe we can use BUILD_BUG_ON_MSG(1, "Unsupported size for xchg"), which could provide more information.

Yes I would prefer there was a message. Please send a v2.

cheers