From: Hannes Reinecke <hare@suse.de>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Justin Tee <justin.tee@broadcom.com>,
James Smart <james.smart@broadcom.com>,
Dick Kennedy <dick.kennedy@broadcom.com>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] scsi: fc: Avoid -Wflex-array-member-not-at-end warnings
Date: Wed, 27 Aug 2025 08:29:13 +0200 [thread overview]
Message-ID: <020f8c5c-c9e4-4ad0-8052-a0b182ded92c@suse.de> (raw)
In-Reply-To: <aK6hbQLyQlvlySf8@kspp>
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 <gustavoars@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 <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@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
next prev parent reply other threads:[~2025-08-27 6:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 6:10 Gustavo A. R. Silva
2025-08-27 6:29 ` Hannes Reinecke [this message]
2025-08-27 16:07 ` Justin Tee
2025-08-31 1:43 ` Martin K. Petersen
2025-09-10 3:04 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=020f8c5c-c9e4-4ad0-8052-a0b182ded92c@suse.de \
--to=hare@suse.de \
--cc=James.Bottomley@hansenpartnership.com \
--cc=dick.kennedy@broadcom.com \
--cc=gustavoars@kernel.org \
--cc=james.smart@broadcom.com \
--cc=justin.tee@broadcom.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®