Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: megaraid_sas: Avoid a couple -Wflex-array-member-not-at-end warnings

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Use the new TRAILING_OVERLAP() helper to fix the following warnings:

drivers/scsi/megaraid/megaraid_sas_fusion.h:1153:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/scsi/megaraid/megaraid_sas_fusion.h:1198:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a
set of MEMBERS that would otherwise follow it --in this case 'struct
MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]' and 'struct
MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]' in the corresponding
structures.

This overlays the trailing members onto the FAM (struct MR_LD_SPAN_MAP
ldSpanMap[];) while keeping the FAM and the start of MEMBERS aligned.

The static_assert() ensures this alignment remains, and it's
intentionally placed inmediately after the corresponding structures --no
blank line in between.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://patch.msgid.link/aM1E7Xa8qYdZ598N@kspp
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Gustavo A. R. Silva and committed by
Martin K. Petersen
81cb6c22 11956e4b

+12 -5
+12 -5
drivers/scsi/megaraid/megaraid_sas_fusion.h
··· 1150 1150 } LD_SPAN_INFO, *PLD_SPAN_INFO; 1151 1151 1152 1152 struct MR_FW_RAID_MAP_ALL { 1153 - struct MR_FW_RAID_MAP raidMap; 1154 - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]; 1153 + /* Must be last --ends in a flexible-array member. */ 1154 + TRAILING_OVERLAP(struct MR_FW_RAID_MAP, raidMap, ldSpanMap, 1155 + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]; 1156 + ); 1155 1157 } __attribute__ ((packed)); 1158 + static_assert(offsetof(struct MR_FW_RAID_MAP_ALL, raidMap.ldSpanMap) == 1159 + offsetof(struct MR_FW_RAID_MAP_ALL, ldSpanMap)); 1156 1160 1157 1161 struct MR_DRV_RAID_MAP { 1158 1162 /* total size of this structure, including this field. ··· 1198 1194 * And it is mainly for code re-use purpose. 1199 1195 */ 1200 1196 struct MR_DRV_RAID_MAP_ALL { 1201 - 1202 - struct MR_DRV_RAID_MAP raidMap; 1203 - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]; 1197 + /* Must be last --ends in a flexible-array member. */ 1198 + TRAILING_OVERLAP(struct MR_DRV_RAID_MAP, raidMap, ldSpanMap, 1199 + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]; 1200 + ); 1204 1201 } __packed; 1202 + static_assert(offsetof(struct MR_DRV_RAID_MAP_ALL, raidMap.ldSpanMap) == 1203 + offsetof(struct MR_DRV_RAID_MAP_ALL, ldSpanMap)); 1205 1204 1206 1205 1207 1206