From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932808AbcBWImg (ORCPT ); Tue, 23 Feb 2016 03:42:36 -0500 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:54720 "EHLO e23smtp02.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbcBWImd (ORCPT ); Tue, 23 Feb 2016 03:42:33 -0500 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com X-IBM-RcptTo: linux-arch@vger.kernel.org;linux-kernel@vger.kernel.org Message-ID: <56CC1AF7.5090300@linux.vnet.ibm.com> Date: Tue, 23 Feb 2016 16:40:23 +0800 From: Pan Xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org CC: Arnd Bergmann Subject: [PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16022308-0005-0000-0000-0000035FA2A6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: pan xinhui __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 --- 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 #include - -extern unsigned long wrong_size_cmpxchg(volatile void *ptr) - __noreturn; +#include /* * 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 #include +#include #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