All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] fs/fat: Fix unaligned __u16 reads for FAT12 access
@ 2017-01-26 20:22 Brüns, Stefan
  2017-01-28 22:46 ` [U-Boot] [U-Boot, " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Brüns, Stefan @ 2017-01-26 20:22 UTC (permalink / raw)
  To: u-boot

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>
Tested-by: Oleksandr Tymoshenko <gonzo@bluezbox.com>
---
 fs/fat/fat.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

v2: added parentheses to fix operator precedence
    added Tested-by: Oleksandr Tymoshenko <gonzo@bluezbox.com>

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index fe899d0442..23ec280071 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);
 
 		if (offset & 0x1)
 			ret >>= 4;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [U-Boot, v2] fs/fat: Fix unaligned __u16 reads for FAT12 access
  2017-01-26 20:22 [U-Boot] [PATCH v2] fs/fat: Fix unaligned __u16 reads for FAT12 access Brüns, Stefan
@ 2017-01-28 22:46 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2017-01-28 22:46 UTC (permalink / raw)
  To: u-boot

On Thu, Jan 26, 2017 at 08:22:36PM +0000, Stefan Br?ns 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>
> Tested-by: Oleksandr Tymoshenko <gonzo@bluezbox.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170128/d84e216f/attachment.sig>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-28 22:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 20:22 [U-Boot] [PATCH v2] fs/fat: Fix unaligned __u16 reads for FAT12 access Brüns, Stefan
2017-01-28 22:46 ` [U-Boot] [U-Boot, " Tom Rini

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.