"Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx> wrote: > -Wflex-array-member-not-at-end was introduced in GCC-14, and we are > getting ready to enable it, globally. > > So, in order to avoid ending up with a flexible-array member in the > middle of multiple other structs, we use the `__struct_group()` > helper to create new tagged structures with the suffix `_hdr`. > These structures group together all the members of the original > flexible structures except the flexible arrays. > > As a result, the arrays are effectively separated from the rest of the > members without modifying the memory layout of the flexible structures. > We then change the type of the middle struct members currently causing > trouble from the original flex struct to the newly created structs with > suffix `_hdr`. > > We also want to ensure that when new members need to be added to the > flexible structures, they are always included within the newly created > tagged structs. For this, we use `static_assert()`. This ensures that the > memory layout for both the flexible structure and the new tagged struct > is the same after any changes. > > This approach avoids having to implement the `_hdr` structures as > completely separate structures, thus preventing having to maintain > two independent but basically identical structures, closing the door > to potential bugs in the future. > > We also use `container_of()` whenever we need to retrieve a pointer to > the flexible structure, through which we can access the flexible-array > member, if necessary. > > Also, remove a couple of unused zero-length arrays and flexible-array > members. > > So, with these changes, fix the following warnings: > > drivers/net/wireless/intel/iwlegacy/commands.h:1196:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:1197:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:2505:30: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:2549:26: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:2654:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:2665:30: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:2673:26: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] > drivers/net/wireless/intel/iwlegacy/commands.h:3349:30: 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@xxxxxxxxxx> Patch applied to wireless-next.git, thanks. a7e8997ae18c wifi: iwlegacy: Avoid multiple -Wflex-array-member-not-at-end warnings -- https://patchwork.kernel.org/project/linux-wireless/patch/Zr2gxERA3RL3EwRe@elsanto/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches