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


Groups > linux.kernel > #1340403 > unrolled thread

[PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size

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

Back to article view | Back to linux.kernel


Contents

  [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

#1340403 — [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size

FromPan Xinhui <xinhui@linux.vnet.ibm.com>
Date2016-02-23 09:50 +0100
Subject[PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
Message-ID<r5gPo-2MH-19@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1340492 — Re: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size

Fromkbuild test robot <lkp@intel.com>
Date2016-02-23 11:10 +0100
SubjectRe: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
Message-ID<r5i4O-3MQ-17@gated-at.bofh.it>
In reply to#1340403

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web