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>

authored by

Gustavo A. R. Silva and committed by
Theodore Ts'o
7e50bbb1 ce7e8a65

+8 -10
+8 -10
fs/ext4/mballoc.c
··· 3037 unsigned char blocksize_bits = min_t(unsigned char, 3038 sb->s_blocksize_bits, 3039 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; 3044 3045 group--; 3046 if (group == 0) ··· 3046 " 2^0 2^1 2^2 2^3 2^4 2^5 2^6 " 3047 " 2^7 2^8 2^9 2^10 2^11 2^12 2^13 ]\n"); 3048 3049 - i = (blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) + 3050 sizeof(struct ext4_group_info); 3051 3052 grinfo = ext4_get_group_info(sb, group); ··· 3066 * We care only about free space counters in the group info and 3067 * these are safe to access even after the buddy has been unloaded 3068 */ 3069 - memcpy(&sg, grinfo, i); 3070 - seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, 3071 - sg.info.bb_fragments, sg.info.bb_first_free); 3072 for (i = 0; i <= 13; i++) 3073 seq_printf(seq, " %-5u", i <= blocksize_bits + 1 ? 3074 - sg.info.bb_counters[i] : 0); 3075 seq_puts(seq, " ]"); 3076 - if (EXT4_MB_GRP_BBITMAP_CORRUPT(&sg.info)) 3077 seq_puts(seq, " Block bitmap corrupted!"); 3078 seq_putc(seq, '\n'); 3079 return 0;
··· 3037 unsigned char blocksize_bits = min_t(unsigned char, 3038 sb->s_blocksize_bits, 3039 EXT4_MAX_BLOCK_LOG_SIZE); 3040 + DEFINE_RAW_FLEX(struct ext4_group_info, sg, bb_counters, 3041 + EXT4_MAX_BLOCK_LOG_SIZE + 2); 3042 3043 group--; 3044 if (group == 0) ··· 3048 " 2^0 2^1 2^2 2^3 2^4 2^5 2^6 " 3049 " 2^7 2^8 2^9 2^10 2^11 2^12 2^13 ]\n"); 3050 3051 + i = (blocksize_bits + 2) * sizeof(sg->bb_counters[0]) + 3052 sizeof(struct ext4_group_info); 3053 3054 grinfo = ext4_get_group_info(sb, group); ··· 3068 * We care only about free space counters in the group info and 3069 * these are safe to access even after the buddy has been unloaded 3070 */ 3071 + memcpy(sg, grinfo, i); 3072 + seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg->bb_free, 3073 + sg->bb_fragments, sg->bb_first_free); 3074 for (i = 0; i <= 13; i++) 3075 seq_printf(seq, " %-5u", i <= blocksize_bits + 1 ? 3076 + sg->bb_counters[i] : 0); 3077 seq_puts(seq, " ]"); 3078 + if (EXT4_MB_GRP_BBITMAP_CORRUPT(sg)) 3079 seq_puts(seq, " Block bitmap corrupted!"); 3080 seq_putc(seq, '\n'); 3081 return 0;