From: Harvey Harrison <harvey.harrison@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Will Newton <will.newton@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Russell King <rmk@arm.linux.org.uk>,
Hirokazu Takata <takata@linux-m32r.org>,
Yoshinori Sato <ysato@users.sourceforge.jp>
Subject: [PATCH-mm 5/7] unaligned: pack the struct, not the struct members
Date: Mon, 17 Nov 2008 19:39:12 -0800 [thread overview]
Message-ID: <1226979552.6150.270.camel@brick> (raw)
This is safe for the arches that currently use this as gcc says that
defining a struct as packed is equivalent to putting packed on each struct
member.
The reason this is needed is that there are some arches that define structs
to be aligned to something greater than a byte...so even if the first member
of the struct is marked as packed, gcc will still treat it as having the
default stuct alignment which will allow it to choose _builtin_memcpy...
see the comments in the memmove-using arches. This also turned out to be
the issue with ARM (needs confirmation) because _some_ ARM compilers
have this alignment set to 4 bytes.
If the struct _itself_ is marked as packed, the compiler cannot assume this default
alignment and _must_ do the bytewise access in whatever way the arch does it. By
making this change, the last 3 arches could move to the new asm-generic version
and the bits in linux/unaligned/ can be removed.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
include/asm-generic/unaligned.h | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
index 8dfca50..ac23e04 100644
--- a/include/asm-generic/unaligned.h
+++ b/include/asm-generic/unaligned.h
@@ -68,9 +68,9 @@ static inline void put_unaligned_be64(u64 val, void *p)
#else /* _UNALIGNED_ACCESS_OK */
-struct __una_u16 { u16 x __attribute__((packed)); };
-struct __una_u32 { u32 x __attribute__((packed)); };
-struct __una_u64 { u64 x __attribute__((packed)); };
+struct __una_u16 { u16 x; } __attribute__((packed));
+struct __una_u32 { u32 x; } __attribute__((packed));
+struct __una_u64 { u64 x; } __attribute__((packed));
static inline u16 __get_le16_noalign(const u8 *p)
{
--
1.6.0.4.994.g16bd3e
reply other threads:[~2008-11-18 3:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1226979552.6150.270.camel@brick \
--to=harvey.harrison@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rmk@arm.linux.org.uk \
--cc=takata@linux-m32r.org \
--cc=torvalds@linux-foundation.org \
--cc=will.newton@gmail.com \
--cc=ysato@users.sourceforge.jp \
/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