From: Ralf Baechle <ralf@linux-mips.org>
To: Imre Kaloz <kaloz@openwrt.org>
Cc: nbd@openwrt.org, linux-mips@linux-mips.org
Subject: Re: [PATCH] use __always_inline for __xchg
Date: Tue, 24 Nov 2009 13:26:01 +0000 [thread overview]
Message-ID: <20091124132601.GA27951@linux-mips.org> (raw)
In-Reply-To: <op.sldiliqr2s3iss@richese>
On Sat, Jan 29, 2005 at 05:54:44PM +0100, Imre Kaloz wrote:
> The following patch changes inline for __xchg to __always_inline in
> include/asm-mips/system.h, following the changes in git. Without this
> 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(volatile __u64 * m, __u64 v
#define __xchg_u64 __xchg_u64_unsupported_on_32bit_kernels
#endif
-/* 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, int size)
{
switch (size) {
@@ -205,11 +201,17 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
case 8:
return __xchg_u64(ptr, x);
}
- __xchg_called_with_bad_pointer();
+
return x;
}
-#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)))); \
+})
extern void set_handler(unsigned long offset, void *addr, unsigned long len);
extern void set_uncached_handler(unsigned long offset, void *addr, unsigned long len);
prev parent reply other threads:[~2009-11-24 13:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-29 16:54 [PATCH] use __always_inline for __xchg Imre Kaloz
2009-11-24 13:26 ` Ralf Baechle [this message]
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=20091124132601.GA27951@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=kaloz@openwrt.org \
--cc=linux-mips@linux-mips.org \
--cc=nbd@openwrt.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.