Re: [PATCH v3][next] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
> 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?

> @@ -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 = {
		...

-Kees

[1] https://web.git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=for-next/kspp&id=29bb79e9dbf1ba100125e39deb7147acd490903f

-- 
Kees Cook




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux