asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
PATCH 1/1 asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
From: pan xinhui <[email protected]>
__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().
--- include/asm-generic/cmpxchg-local.h | 8 +++----- include/asm-generic/cmpxchg.h | 9 ++------- 2 files changed, 5 insertions(+), 12 deletions(-)
include/asm-generic/cmpxchg-local.h +3 -5
@@ -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;
include/asm-generic/cmpxchg.h +2 -7
@@ -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; } }
Signature · 1 line
2.5.0
kbuild test robot
build botreproduce: 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…
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