Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1340403
| From | Pan Xinhui <xinhui@linux.vnet.ibm.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size |
| Date | 2016-02-23 09:50 +0100 |
| Message-ID | <r5gPo-2MH-19@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
__xchg_called_with_bad_pointer/wrong_size_cmpxchg 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().
Signed-off-by: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
---
include/asm-generic/cmpxchg-local.h | 8 +++-----
include/asm-generic/cmpxchg.h | 9 ++-------
2 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/include/asm-generic/cmpxchg-local.h b/include/asm-generic/cmpxchg-local.h
index 70bef78..6d78291 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -3,9 +3,7 @@
#include <linux/types.h>
#include <linux/irqflags.h>
-
-extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
- __noreturn;
+#include <linux/bug.h>
/*
* Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
@@ -20,7 +18,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,
* Sanity checking, compile-time.
*/
if (size == 8 && sizeof(unsigned long) != 8)
- wrong_size_cmpxchg(ptr);
+ BUILD_BUG();
raw_local_irq_save(flags);
switch (size) {
@@ -41,7 +39,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile void *ptr,
*(u64 *)ptr = (u64)new;
break;
default:
- wrong_size_cmpxchg(ptr);
+ BUILD_BUG();
}
raw_local_irq_restore(flags);
return prev;
diff --git a/include/asm-generic/cmpxchg.h b/include/asm-generic/cmpxchg.h
index e5f9080..ffaa4ce 100644
--- a/include/asm-generic/cmpxchg.h
+++ b/include/asm-generic/cmpxchg.h
@@ -12,15 +12,10 @@
#include <linux/types.h>
#include <linux/irqflags.h>
+#include <linux/bug.h>
#ifndef xchg
-/*
- * This function doesn't exist, so you'll get a linker error if
- * something tries to do an invalidly-sized xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
static inline
unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
{
@@ -74,7 +69,7 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
#endif /* CONFIG_64BIT */
default:
- __xchg_called_with_bad_pointer();
+ BUILD_BUG();
return x;
}
}
--
2.5.0
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size Pan Xinhui <xinhui@linux.vnet.ibm.com> - 2016-02-23 09:50 +0100
Re: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size kbuild test robot <lkp@intel.com> - 2016-02-23 11:10 +0100
csiph-web