Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1340549 > unrolled thread

[PATCH V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size

Started byPan Xinhui <xinhui@linux.vnet.ibm.com>
First post2016-02-23 12:10 +0100
Last post2016-02-29 12:10 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit  {cmp}xchg size Pan Xinhui <xinhui@linux.vnet.ibm.com> - 2016-02-23 12:10 +0100
    Re: [V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size Michael Ellerman <mpe@ellerman.id.au> - 2016-02-29 12:10 +0100

#1340549 — [PATCH V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size

FromPan Xinhui <xinhui@linux.vnet.ibm.com>
Date2016-02-23 12:10 +0100
Subject[PATCH V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size
Message-ID<r5j0S-4sa-19@gated-at.bofh.it>
From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>

__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 a kind of issues easily, we use BUILD_BUG_ON_MSG() here.

Signed-off-by: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
---
change from V1:
	use BUILD_BUG_ON_MSG to provide more build error messages.
---
 arch/powerpc/include/asm/cmpxchg.h | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/include/asm/cmpxchg.h b/arch/powerpc/include/asm/cmpxchg.h
index d1a8d93..730028b 100644
--- a/arch/powerpc/include/asm/cmpxchg.h
+++ b/arch/powerpc/include/asm/cmpxchg.h
@@ -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_ON_MSG(1, "Unsupported size for __xchg");
 	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_ON_MSG(1, "Unsupported size for __xchg_local");
 	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_ON_MSG(1, "Unsupported size for __cmpxchg");
 	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_ON_MSG(1, "Unsupported size for __cmpxchg_local");
 	return old;
 }
 
-- 
2.5.0

[toc] | [next] | [standalone]


#1345661 — Re: [V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size

FromMichael Ellerman <mpe@ellerman.id.au>
Date2016-02-29 12:10 +0100
SubjectRe: [V2] arch/powerpc: use BUILD_BUG_ON_MSG() when detect unfit {cmp}xchg size
Message-ID<r7tSb-2et-37@gated-at.bofh.it>
In reply to#1340549
On Tue, 2016-23-02 at 11:05:01 UTC, xinhui wrote:
> From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
> 
> __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 a kind of issues easily, we use BUILD_BUG_ON_MSG() here.
> 
> Signed-off-by: pan xinhui <xinhui.pan@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/10d8b1480e6966ba03cd3afad3

cheers

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web