ext4: avoid variable size array in structs armv7-master-clang-v4.13-rc4
authorStefan Agner <stefan@agner.ch>
Mon, 7 Aug 2017 07:03:10 +0000 (00:03 -0700)
committerStefan Agner <stefan@agner.ch>
Mon, 7 Aug 2017 07:03:10 +0000 (00:03 -0700)
Clang does not support variable length array in structure, even
if the array is at the very end. Avoid variable sized array by
using the maximum length again. This fixes clang build error:

fs/ext4/mballoc.c:2303:17: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
                ext4_grpblk_t counters[blocksize_bits + 2];

Fixes: 2df2c3402fc8 ("ext4: fix warning about stack corruption")
Signed-off-by: Stefan Agner <stefan@agner.ch>
fs/ext4/mballoc.c

index 5a1052627a81413685241f0c4669bbf755e2c5f9..073e580470be84db1336fda784088cca0b0e5741 100644 (file)
@@ -2300,7 +2300,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
                                             EXT4_MAX_BLOCK_LOG_SIZE);
        struct sg {
                struct ext4_group_info info;
-               ext4_grpblk_t counters[blocksize_bits + 2];
+               ext4_grpblk_t counters[EXT4_MAX_BLOCK_LOG_SIZE + 2];
        } sg;
 
        group--;
@@ -2320,7 +2320,9 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
                buddy_loaded = 1;
        }
 
-       memcpy(&sg, ext4_get_group_info(sb, group), sizeof(sg));
+       i = (blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) +
+               sizeof(struct ext4_group_info);
+       memcpy(&sg, ext4_get_group_info(sb, group), i);
 
        if (buddy_loaded)
                ext4_mb_unload_buddy(&e4b);