]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
ext4fs: le32_to_cpu() used on a 16-bit field
authorRommel Custodio <sessyargc+uboot@gmail.com>
Sun, 21 Jul 2013 08:53:25 +0000 (10:53 +0200)
committerTom Rini <trini@ti.com>
Mon, 22 Jul 2013 14:09:30 +0000 (10:09 -0400)
Fix reading ext4_extent_header struture on BE machines.  Some 16 bit
fields where converted to 32 bit fields, due to the byte swap on BE
machines the containing value was corrupted. Therefore reading ext4
filesystems on BE machines where broken before.

Signed-off-by: Rommel Custodio <sessyargc+uboot@gmail.com>
[sent via git-send-email; rework commit message]
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
fs/ext4/ext4_common.c

index 277629380f33e357ee8ea0d1b0497c932dca705c..ff9c4ecd935274913feb270aa55d0ec98f0af2a3 100644 (file)
@@ -1432,7 +1432,7 @@ static struct ext4_extent_header *ext4fs_get_extent_block
        while (1) {
                index = (struct ext4_extent_idx *)(ext_block + 1);
 
-               if (le32_to_cpu(ext_block->eh_magic) != EXT4_EXT_MAGIC)
+               if (le16_to_cpu(ext_block->eh_magic) != EXT4_EXT_MAGIC)
                        return 0;
 
                if (ext_block->eh_depth == 0)
@@ -1440,14 +1440,14 @@ static struct ext4_extent_header *ext4fs_get_extent_block
                i = -1;
                do {
                        i++;
-                       if (i >= le32_to_cpu(ext_block->eh_entries))
+                       if (i >= le16_to_cpu(ext_block->eh_entries))
                                break;
                } while (fileblock > le32_to_cpu(index[i].ei_block));
 
                if (--i < 0)
                        return 0;
 
-               block = le32_to_cpu(index[i].ei_leaf_hi);
+               block = le16_to_cpu(index[i].ei_leaf_hi);
                block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo);
 
                if (ext4fs_devread((lbaint_t)block << log2_blksz, 0, fs->blksz,
@@ -1548,17 +1548,17 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
 
                do {
                        i++;
-                       if (i >= le32_to_cpu(ext_block->eh_entries))
+                       if (i >= le16_to_cpu(ext_block->eh_entries))
                                break;
                } while (fileblock >= le32_to_cpu(extent[i].ee_block));
                if (--i >= 0) {
                        fileblock -= le32_to_cpu(extent[i].ee_block);
-                       if (fileblock >= le32_to_cpu(extent[i].ee_len)) {
+                       if (fileblock >= le16_to_cpu(extent[i].ee_len)) {
                                free(buf);
                                return 0;
                        }
 
-                       start = le32_to_cpu(extent[i].ee_start_hi);
+                       start = le16_to_cpu(extent[i].ee_start_hi);
                        start = (start << 32) +
                                        le32_to_cpu(extent[i].ee_start_lo);
                        free(buf);