Skip to content

Commit 7e50bbb

Browse files
GustavoARSilvatytso
authored andcommitted
ext4: avoid -Wflex-array-member-not-at-end warning
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Use the `DEFINE_RAW_FLEX()` helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly. So, with these changes, fix the following warning: fs/ext4/mballoc.c:3041:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <kees@kernel.org> Link: https://patch.msgid.link/Z-SF97N3AxcIMlSi@kspp Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent ce7e8a6 commit 7e50bbb

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

fs/ext4/mballoc.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,18 +3037,16 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
30373037
unsigned char blocksize_bits = min_t(unsigned char,
30383038
sb->s_blocksize_bits,
30393039
EXT4_MAX_BLOCK_LOG_SIZE);
3040-
struct sg {
3041-
struct ext4_group_info info;
3042-
ext4_grpblk_t counters[EXT4_MAX_BLOCK_LOG_SIZE + 2];
3043-
} sg;
3040+
DEFINE_RAW_FLEX(struct ext4_group_info, sg, bb_counters,
3041+
EXT4_MAX_BLOCK_LOG_SIZE + 2);
30443042

30453043
group--;
30463044
if (group == 0)
30473045
seq_puts(seq, "#group: free frags first ["
30483046
" 2^0 2^1 2^2 2^3 2^4 2^5 2^6 "
30493047
" 2^7 2^8 2^9 2^10 2^11 2^12 2^13 ]\n");
30503048

3051-
i = (blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) +
3049+
i = (blocksize_bits + 2) * sizeof(sg->bb_counters[0]) +
30523050
sizeof(struct ext4_group_info);
30533051

30543052
grinfo = ext4_get_group_info(sb, group);
@@ -3068,14 +3066,14 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
30683066
* We care only about free space counters in the group info and
30693067
* these are safe to access even after the buddy has been unloaded
30703068
*/
3071-
memcpy(&sg, grinfo, i);
3072-
seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
3073-
sg.info.bb_fragments, sg.info.bb_first_free);
3069+
memcpy(sg, grinfo, i);
3070+
seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg->bb_free,
3071+
sg->bb_fragments, sg->bb_first_free);
30743072
for (i = 0; i <= 13; i++)
30753073
seq_printf(seq, " %-5u", i <= blocksize_bits + 1 ?
3076-
sg.info.bb_counters[i] : 0);
3074+
sg->bb_counters[i] : 0);
30773075
seq_puts(seq, " ]");
3078-
if (EXT4_MB_GRP_BBITMAP_CORRUPT(&sg.info))
3076+
if (EXT4_MB_GRP_BBITMAP_CORRUPT(sg))
30793077
seq_puts(seq, " Block bitmap corrupted!");
30803078
seq_putc(seq, '\n');
30813079
return 0;

0 commit comments

Comments
 (0)