From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>,
nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v3][next] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings
Date: Wed, 25 Jun 2025 11:31:33 -0600 [thread overview]
Message-ID: <e0adad17-5d4f-4309-9975-81971597da65@embeddedor.com> (raw)
In-Reply-To: <202506250950.31C8A58E@keescook>
On 25/06/25 10:56, Kees Cook wrote:
> On Wed, Jun 11, 2025 at 01:52:41PM -0600, Gustavo A. R. Silva wrote:
>> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
>> getting ready to enable it, globally.
>>
>> Refactor multiple structs that contain flexible-array members in the
>> middle by replacing them with unions.
>>
>> These changes preserve the memory layout while effectively adjusting
>> it so that the flexible-array member is always treated as the last
>> member.
>>
>> With these changes, fix a dozen instances of the following type of
>> warning:
>>
>> drivers/acpi/nfit/intel.c:692:35: 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 v3:
>> - Use union instead of DEFINE_RAW_FLEX().
>
> I think your TRAILING_OVERLAP macro[1] is perfect here. I'll try to get that
> landed for the next rc. Can you double-check that this works correctly
> in these cases?
Absolutely. If people prefer that route I'm happy to wait for the helper to
land in linus' tree.
>
>> @@ -55,9 +55,16 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm,
>> {
>> struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
>> unsigned long security_flags = 0;
>> - struct {
>> + /*
>> + * This effectively creates a union between the flexible-array member
>> + * and any members after _offset_to_fam.
>> + */
>> + union {
>> struct nd_cmd_pkg pkg;
>> - struct nd_intel_get_security_state cmd;
>> + struct {
>> + u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)];
>> + struct nd_intel_get_security_state cmd;
>> + };
>> } nd_cmd = {
>> .pkg = {
>> .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
>
> I think it would be a pretty small and direct replacement:
>
> TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload,
> struct nd_intel_get_security_state cmd;
> ) nd_cmd = {
> ...
Yes, this works. Hopefully, maintainers will comment on this and let us
know what they prefer. :)
Thanks!
-Gustavo
>
> -Kees
>
> [1] https://web.git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=for-next/kspp&id=29bb79e9dbf1ba100125e39deb7147acd490903f
>
next prev parent reply other threads:[~2025-06-25 17:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 19:52 Gustavo A. R. Silva
2025-06-24 19:46 ` Gustavo A. R. Silva
2025-06-25 16:56 ` Kees Cook
2025-06-25 17:31 ` Gustavo A. R. Silva [this message]
2025-06-25 20:33 ` dan.j.williams
2025-06-25 21:08 ` dan.j.williams
2025-06-25 21:43 ` Gustavo A. R. Silva
2025-06-25 22:24 ` dan.j.williams
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=e0adad17-5d4f-4309-9975-81971597da65@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=gustavoars@kernel.org \
--cc=ira.weiny@intel.com \
--cc=kees@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=rafael@kernel.org \
--cc=vishal.l.verma@intel.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®