public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pan Xinhui <xinhui@linux.vnet.ibm.com>
To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size
Date: Tue, 23 Feb 2016 16:40:23 +0800	[thread overview]
Message-ID: <56CC1AF7.5090300@linux.vnet.ibm.com> (raw)

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

             reply	other threads:[~2016-02-23  8:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23  8:40 Pan Xinhui [this message]
2016-02-23 10:05 ` [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56CC1AF7.5090300@linux.vnet.ibm.com \
    --to=xinhui@linux.vnet.ibm.com \
    --cc=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox