Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Tue, 24 Nov 2009
 06:26:25 -0700
Received: from mail2.lsil.com (mail2.lsil.com [147.145.40.22])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id nAODQPQ3005232	for
 <andy.sharp@lsi.com>; Tue, 24 Nov 2009 05:26:25 -0800
Received: from psmtp.com (na3sys009amx179.postini.com [74.125.149.160])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id nAODMLew024742	for
 <andy.sharp@lsi.com>; Tue, 24 Nov 2009 05:22:21 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx179.postini.com
 ([74.125.148.14]) with SMTP;	Tue, 24 Nov 2009 08:26:24 EST
Received: from localhost.localdomain ([127.0.0.1]:57104 "EHLO
	eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL)	by eddie.linux-mips.org with
 ESMTP id S1492421AbZKXN0J (ORCPT	<rfc822;andy.sharp@lsi.com>); Tue, 24 Nov
 2009 14:26:09 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Tue, 24 Nov 2009 14:25:52
 +0100 (CET)
Received: from h5.dl5rb.org.uk ([81.2.74.5]:45245 "EHLO h5.dl5rb.org.uk"
	rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP	id
 S1492387AbZKXNZp (ORCPT <rfc822;linux-mips@linux-mips.org>);	Tue, 24 Nov 2009
 14:25:45 +0100
Received: from h5.dl5rb.org.uk (localhost.localdomain [127.0.0.1])	by
 h5.dl5rb.org.uk (8.14.3/8.14.3) with ESMTP id nAODQ2iB028082;	Tue, 24 Nov
 2009 13:26:02 GMT
Received: (from ralf@localhost)	by h5.dl5rb.org.uk (8.14.3/8.14.3/Submit) id
 nAODQ1Y3028080;	Tue, 24 Nov 2009 13:26:01 GMT
From: Ralf Baechle <ralf@linux-mips.org>
To: Imre Kaloz <kaloz@openwrt.org>
CC: "nbd@openwrt.org" <nbd@openwrt.org>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Tue, 24 Nov 2009 06:26:01 -0700
Subject: Re: [PATCH] use __always_inline for __xchg
Thread-Topic: [PATCH] use __always_inline for __xchg
Thread-Index: AcptCblIyb+SV/gXT8OaBzprmSNBQw==
Message-ID: <20091124132601.GA27951@linux-mips.org>
References: <op.sldiliqr2s3iss@richese>
In-Reply-To: <op.sldiliqr2s3iss@richese>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:99.90000/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <ralf@linux-mips.org> [22/1] 
x-pstn-neptune: 0/0/0.00/0
user-agent: Mutt/1.5.19 (2009-01-05)
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

On Sat, Jan 29, 2005 at 05:54:44PM +0100, Imre Kaloz wrote:

> The following patch changes inline for __xchg to __always_inline in =20
> include/asm-mips/system.h, following the changes in git. Without this =20
> change linking the kernel fails.
>
> Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>

Imre just pointed me at this antique patch again saying it was still needed=
.
Back then I ditched it because I couldn't see what the problem it was
trying to fix was - but after a little brainstorming it got obvious.

Now I don't like __always_inline which forces the optimizer to do things
which may not really be what we want, for example when building with -Os
so I found a different fix using BUILD_BUG_ON().  Patch below.

Cheers,

  Ralf

From: Ralf Baechle <ralf@linux-mips.org>

MIPS: Fix build error if __xchg() is not getting inlined.

If __xchg() is not getting inlined the outline version of the function
will have a reference to __xchg_called_with_bad_pointer() which does not
exist remaining.  Fixed by using BUILD_BUG_ON() xchg() to check for
allowable operand sizes.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.=
h
index fcf5f98..587a48a 100644
--- a/arch/mips/include/asm/system.h
+++ b/arch/mips/include/asm/system.h
@@ -193,10 +193,6 @@ extern __u64 __xchg_u64_unsupported_on_32bit_kernels(v=
olatile __u64 * m, __u64 v
 #define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
 #endif
=20
-/* This function doesn't exist, so you'll get a linker error
-   if something tries to do an invalid xchg().  */
-extern void __xchg_called_with_bad_pointer(void);
-
 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, i=
nt size)
 {
 	switch (size) {
@@ -205,11 +201,17 @@ static inline unsigned long __xchg(unsigned long x, v=
olatile void * ptr, int siz
 	case 8:
 		return __xchg_u64(ptr, x);
 	}
-	__xchg_called_with_bad_pointer();
+
 	return x;
 }
=20
-#define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr)=
, sizeof(*(ptr))))
+#define xchg(ptr, x)							\
+({									\
+	BUILD_BUG_ON(sizeof(*(ptr)) & ~0xc);				\
+									\
+	((__typeof__(*(ptr)))						\
+		__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))));	\
+})
=20
 extern void set_handler(unsigned long offset, void *addr, unsigned long le=
n);
 extern void set_uncached_handler(unsigned long offset, void *addr, unsigne=
d long len);

