Skip to content
Snippets Groups Projects
Commit b352caea authored by Stefan Brüns's avatar Stefan Brüns Committed by Tom Rini
Browse files

fs/fat: Fix unaligned __u16 reads for FAT12 access


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 8d48c92b

Reported-by: default avatarOleksandr Tymoshenko <gonzo@bluezbox.com>
Signed-off-by: default avatarStefan Brüns <stefan.bruens@rwth-aachen.de>
Tested-by: default avatarOleksandr Tymoshenko <gonzo@bluezbox.com>
parent a55bed12
No related branches found
No related tags found
No related merge requests found
...@@ -179,7 +179,7 @@ int flush_dirty_fat_buffer(fsdata *mydata) ...@@ -179,7 +179,7 @@ int flush_dirty_fat_buffer(fsdata *mydata)
static __u32 get_fatent(fsdata *mydata, __u32 entry) static __u32 get_fatent(fsdata *mydata, __u32 entry)
{ {
__u32 bufnum; __u32 bufnum;
__u32 off16, offset; __u32 offset, off8;
__u32 ret = 0x00; __u32 ret = 0x00;
if (CHECK_CLUST(entry, mydata->fatsize)) { if (CHECK_CLUST(entry, mydata->fatsize)) {
...@@ -242,8 +242,9 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry) ...@@ -242,8 +242,9 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]); ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
break; break;
case 12: case 12:
off16 = (offset * 3) / 2; off8 = (offset * 3) / 2;
ret = FAT2CPU16(*(__u16 *)(mydata->fatbuf + off16)); /* fatbut + off8 may be unaligned, read in byte granularity */
ret = mydata->fatbuf[off8] + (mydata->fatbuf[off8 + 1] << 8);
if (offset & 0x1) if (offset & 0x1)
ret >>= 4; ret >>= 4;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment