On 8/27/25 08:10, Gustavo A. R. Silva wrote:
-Wflex-array-member-not-at-end has been 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 a new tagged `struct fc_df_desc_fpin_reg_hdr`.
This structure groups together all the members of the flexible
`struct fc_df_desc_fpin_reg` except the flexible array.
As a result, the array is effectively separated from the rest of the
members without modifying the memory layout of the flexible structure.
We then change the type of the middle struct members currently causing
trouble from `struct fc_df_desc_fpin_reg` to `struct
fc_df_desc_fpin_reg_hdr`.
We also want to ensure that in case new members need to be added to the
flexible structure, they are always included within the newly created
tagged struct. 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 `struct fc_df_desc_fpin_reg_hdr`
as a completely separate structure, thus preventing having to maintain
two independent but basically identical structures, closing the door
to potential bugs in the future.
The above is also done for flexible structures `struct fc_els_rdf` and
`struct fc_els_rdf_resp`
So, with these changes, fix the following warnings:
drivers/scsi/lpfc/lpfc_hw4.h:4936:41: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
drivers/scsi/lpfc/lpfc_hw4.h:4942:41: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
drivers/scsi/lpfc/lpfc_hw4.h:4947:41: 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 <gustavo...@kernel.org>
---
Changes in v2:
- Implement the same changes for `struct fc_els_rdf_resp`
- Fix size calculation in lpfc_issue_els_rdf(). (Justin Tee)
v1:
- Link: https://lore.kernel.org/linux-hardening/aJtMETERd-geyP1q@kspp/
include/uapi/scsi/fc/fc_els.h | 58 +++++++++++++++++++++++------------
drivers/scsi/lpfc/lpfc_els.c | 2 +-
drivers/scsi/lpfc/lpfc_hw4.h | 6 ++--
3 files changed, 43 insertions(+), 23 deletions(-)
Reviewed-by: Hannes Reinecke <h...@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
h...@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich