All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Tymoshenko <gonzo@bluezbox.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fs/fat: Fix unaligned __u16 reads for FAT12 access
Date: Thu, 26 Jan 2017 11:50:19 -0800	[thread overview]
Message-ID: <20170126195019.GA398@bluezbox.com> (raw)
In-Reply-To: <2b77133c2d5a409793fcd8d4764b40fc@rwthex-w2-b.rwth-ad.de>

Br?ns, Stefan (Stefan.Bruens at rwth-aachen.de) wrote:
> Doing unaligned reads is not supported on all architectures, use
> byte sized reads of the little endian buffer.
> Rename off16 to off8, as it reflects the buffer offset in byte
> granularity (offset is in entry, i.e. 12 bit, granularity).
> Fix a regression introduced in 8d48c92b45aea91e2a2be90f2ed93677e85526f1
> 
> Reported-by: Oleksandr Tymoshenko <gonzo@bluezbox.com>
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  fs/fat/fat.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index fe899d0442..06088e2421 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -179,7 +179,7 @@ int flush_dirty_fat_buffer(fsdata *mydata)
>  static __u32 get_fatent(fsdata *mydata, __u32 entry)
>  {
>  	__u32 bufnum;
> -	__u32 off16, offset;
> +	__u32 offset, off8;
>  	__u32 ret = 0x00;
>  
>  	if (CHECK_CLUST(entry, mydata->fatsize)) {
> @@ -242,8 +242,9 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
>  		ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
>  		break;
>  	case 12:
> -		off16 = (offset * 3) / 2;
> -		ret = FAT2CPU16(*(__u16 *)(mydata->fatbuf + off16));
> +		off8 = (offset * 3) / 2;
> +		/* fatbut + off8 may be unaligned, read in byte granularity */
> +		ret = mydata->fatbuf[off8] + mydata->fatbuf[off8 + 1] << 8;

This patch when applied gives me "Invalid FAT entry" message. Reason
is: operator '<<' has lower precedence than '+' so this expression is
equivalent to (mydata->fatbuf[off8] + mydata->fatbuf[off8 + 1]) << 8
With explicit parentheses around shift it works as expected:

ret = mydata->fatbuf[off8] + (mydata->fatbuf[off8 + 1] << 8);

-- 
gonzo

      reply	other threads:[~2017-01-26 19:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 23:25 [U-Boot] FAT12 regression after 8d48c92b45aea91e2a2be90f2ed93677e85526f1 Oleksandr Tymoshenko
2017-01-26  6:40 ` Heiko Schocher
2017-01-26 17:55 ` [U-Boot] [PATCH] fs/fat: Fix unaligned __u16 reads for FAT12 access Brüns, Stefan
2017-01-26 19:50   ` Oleksandr Tymoshenko [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=20170126195019.GA398@bluezbox.com \
    --to=gonzo@bluezbox.com \
    --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 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.