From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] mtd: onenand: Fix unaligned access
Date: Sat, 28 Dec 2013 00:07:42 +0100 [thread overview]
Message-ID: <201312280007.42883.marex@denx.de> (raw)
In-Reply-To: <1388016086-20293-1-git-send-email-marex@denx.de>
On Thursday, December 26, 2013 at 01:01:24 AM, Marek Vasut wrote:
> Fix unaligned access in OneNAND core. The problem is that the ffchars[]
> array is an array of "unsigned char", but in onenand_write_ops_nolock()
> can be passed to the memcpy_16() function. The memcpy_16() function will
> treat the buffer as an array of "unsigned short", thus triggering
> unaligned access if the compiler decided ffchars[] to be not aligned.
>
> I managed to trigger the problem with regular ELDK 5.4 GCC compiler.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Albert Aribaud <albert.u.boot@aribaud.net>
> Cc: Scott Wood <scottwood@freescale.com>
> Cc: Tom Rini <trini@ti.com>
> ---
> drivers/mtd/onenand/onenand_base.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/onenand/onenand_base.c
> b/drivers/mtd/onenand/onenand_base.c index 979e4af..e33e8d3 100644
> --- a/drivers/mtd/onenand/onenand_base.c
> +++ b/drivers/mtd/onenand/onenand_base.c
> @@ -91,7 +91,13 @@ static struct nand_ecclayout onenand_oob_32 = {
> .oobfree = { {2, 3}, {14, 2}, {18, 3}, {30, 2} }
> };
>
> -static const unsigned char ffchars[] = {
> +/*
> + * Warning! This array is used with the memcpy_16() function, thus
> + * it must be aligned to 2 bytes. GCC can make this array unaligned
> + * as the array is made of unsigned char, which memcpy16() doesn't
> + * like and will cause unaligned access.
> + */
> +static const unsigned char __aligned(2) ffchars[] = {
> 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
> 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 16 */
> 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
Lukasz, can you please review this one?
Best regards,
Marek Vasut
next prev parent reply other threads:[~2013-12-27 23:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-26 0:01 [U-Boot] [PATCH 1/3] mtd: onenand: Fix unaligned access Marek Vasut
2013-12-26 0:01 ` [U-Boot] [PATCH 2/3] ARM: pxa: Fix OneNAND SPL builds Marek Vasut
2013-12-26 0:01 ` [U-Boot] [PATCH 3/3] ARM: pxa: Fix OneNAND window access on VPAC270 Marek Vasut
2013-12-26 23:23 ` [U-Boot] [PATCH 1/3] mtd: onenand: Fix unaligned access Rommel G Custodio
2013-12-27 21:19 ` Scott Wood
2013-12-27 23:07 ` Marek Vasut [this message]
2013-12-28 16:06 ` Lukasz Majewski
2013-12-29 10:16 ` Marek Vasut
2013-12-31 10:43 ` Lukasz Majewski
2014-01-01 19:32 ` Marek Vasut
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=201312280007.42883.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/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