* [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
@ 2016-02-23 8:40 Pan Xinhui
2016-02-23 10:05 ` kbuild test robot
0 siblings, 1 reply; 2+ messages in thread
From: Pan Xinhui @ 2016-02-23 8:40 UTC (permalink / raw)
To: linux-arch, linux-kernel; +Cc: Arnd Bergmann
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
2016-02-23 8:40 [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size Pan Xinhui
@ 2016-02-23 10:05 ` kbuild test robot
0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2016-02-23 10:05 UTC (permalink / raw)
To: Pan Xinhui; +Cc: kbuild-all, linux-arch, linux-kernel, Arnd Bergmann
[-- Attachment #1: Type: text/plain, Size: 2207 bytes --]
Hi pan,
[auto build test ERROR on v4.5-rc5]
[also build test ERROR on next-20160223]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Pan-Xinhui/asm-generic-cmpxchg-use-BUILD_BUG-when-detect-unfit-cmp-xchg-size/20160223-164522
config: parisc-c3000_defconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc
All errors (new ones prefixed by >>):
In file included from arch/parisc/include/asm/cmpxchg.h:81:0,
from arch/parisc/include/asm/atomic.h:9,
from include/linux/atomic.h:4,
from arch/parisc/include/asm/bitops.h:12,
from include/linux/bitops.h:36,
from include/linux/kernel.h:10,
from arch/parisc/include/asm/bug.h:4,
from include/linux/bug.h:4,
from include/linux/page-flags.h:9,
from kernel/bounds.c:9:
include/asm-generic/cmpxchg-local.h: In function '__cmpxchg_local_generic':
>> include/asm-generic/cmpxchg-local.h:21:3: error: implicit declaration of function 'BUILD_BUG' [-Werror=implicit-function-declaration]
BUILD_BUG();
^
cc1: some warnings being treated as errors
make[2]: *** [kernel/bounds.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [sub-make] Error 2
vim +/BUILD_BUG +21 include/asm-generic/cmpxchg-local.h
15 unsigned long flags, prev;
16
17 /*
18 * Sanity checking, compile-time.
19 */
20 if (size == 8 && sizeof(unsigned long) != 8)
> 21 BUILD_BUG();
22
23 raw_local_irq_save(flags);
24 switch (size) {
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 13835 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-23 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23 8:40 [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size Pan Xinhui
2016-02-23 10:05 ` kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox