* [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings @ 2025-06-25 21:42 Gustavo A. R. Silva 2025-06-26 0:17 ` dan.j.williams ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: Gustavo A. R. Silva @ 2025-06-25 21:42 UTC (permalink / raw) To: Kees Cook, Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki, Len Brown Cc: nvdimm, linux-acpi, linux-kernel, Gustavo A. R. Silva, linux-hardening -Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Use the new TRAILING_OVERLAP() helper to 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] Acked-by: Dan Williams <dan.j.williams@intel.com> Tested-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> --- This patch should go through: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/ (for-next/hardening) Changes in v4: - Use the new TRAILING_OVERLAP() helper. Changes in v3: - Use union instead of DEFINE_RAW_FLEX(). - Link: https://lore.kernel.org/linux-hardening/aEneid7gdAZr1_kR@kspp/ Changes in v2: - Use DEFINE_RAW_FLEX() instead of __struct_group(). - Link: https://lore.kernel.org/linux-hardening/Z-QpUcxFCRByYcTA@kspp/ v1: - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/ drivers/acpi/nfit/intel.c | 84 +++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c index 3902759abcba..d0b72e906428 100644 --- a/drivers/acpi/nfit/intel.c +++ b/drivers/acpi/nfit/intel.c @@ -55,10 +55,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm, { struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); unsigned long security_flags = 0; - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_get_security_state cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_get_security_state cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE, .nd_family = NVDIMM_FAMILY_INTEL, @@ -120,10 +119,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm, static int intel_security_freeze(struct nvdimm *nvdimm) { struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_freeze_lock cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_freeze_lock cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_FREEZE_LOCK, .nd_family = NVDIMM_FAMILY_INTEL, @@ -153,10 +151,9 @@ static int intel_security_change_key(struct nvdimm *nvdimm, unsigned int cmd = ptype == NVDIMM_MASTER ? NVDIMM_INTEL_SET_MASTER_PASSPHRASE : NVDIMM_INTEL_SET_PASSPHRASE; - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_set_passphrase cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_set_passphrase cmd; + ) nd_cmd = { .pkg = { .nd_family = NVDIMM_FAMILY_INTEL, .nd_size_in = ND_INTEL_PASSPHRASE_SIZE * 2, @@ -195,10 +192,9 @@ static int __maybe_unused intel_security_unlock(struct nvdimm *nvdimm, const struct nvdimm_key_data *key_data) { struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_unlock_unit cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_unlock_unit cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_UNLOCK_UNIT, .nd_family = NVDIMM_FAMILY_INTEL, @@ -234,10 +230,9 @@ static int intel_security_disable(struct nvdimm *nvdimm, { int rc; struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_disable_passphrase cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_disable_passphrase cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_DISABLE_PASSPHRASE, .nd_family = NVDIMM_FAMILY_INTEL, @@ -277,10 +272,9 @@ static int __maybe_unused intel_security_erase(struct nvdimm *nvdimm, struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); unsigned int cmd = ptype == NVDIMM_MASTER ? NVDIMM_INTEL_MASTER_SECURE_ERASE : NVDIMM_INTEL_SECURE_ERASE; - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_secure_erase cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_secure_erase cmd; + ) nd_cmd = { .pkg = { .nd_family = NVDIMM_FAMILY_INTEL, .nd_size_in = ND_INTEL_PASSPHRASE_SIZE, @@ -318,10 +312,9 @@ static int __maybe_unused intel_security_query_overwrite(struct nvdimm *nvdimm) { int rc; struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_query_overwrite cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_query_overwrite cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_QUERY_OVERWRITE, .nd_family = NVDIMM_FAMILY_INTEL, @@ -354,10 +347,9 @@ static int __maybe_unused intel_security_overwrite(struct nvdimm *nvdimm, { int rc; struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_overwrite cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_overwrite cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_OVERWRITE, .nd_family = NVDIMM_FAMILY_INTEL, @@ -407,10 +399,9 @@ const struct nvdimm_security_ops *intel_security_ops = &__intel_security_ops; static int intel_bus_fwa_businfo(struct nvdimm_bus_descriptor *nd_desc, struct nd_intel_bus_fw_activate_businfo *info) { - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_bus_fw_activate_businfo cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_bus_fw_activate_businfo cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, .nd_family = NVDIMM_BUS_FAMILY_INTEL, @@ -518,10 +509,9 @@ static enum nvdimm_fwa_capability intel_bus_fwa_capability( static int intel_bus_fwa_activate(struct nvdimm_bus_descriptor *nd_desc) { struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_bus_fw_activate cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_bus_fw_activate cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE, .nd_family = NVDIMM_BUS_FAMILY_INTEL, @@ -582,10 +572,9 @@ const struct nvdimm_bus_fw_ops *intel_bus_fw_ops = &__intel_bus_fw_ops; static int intel_fwa_dimminfo(struct nvdimm *nvdimm, struct nd_intel_fw_activate_dimminfo *info) { - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_fw_activate_dimminfo cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_fw_activate_dimminfo cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO, .nd_family = NVDIMM_FAMILY_INTEL, @@ -688,10 +677,9 @@ static int intel_fwa_arm(struct nvdimm *nvdimm, enum nvdimm_fwa_trigger arm) { struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); struct acpi_nfit_desc *acpi_desc = nfit_mem->acpi_desc; - struct { - struct nd_cmd_pkg pkg; - struct nd_intel_fw_activate_arm cmd; - } nd_cmd = { + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, + struct nd_intel_fw_activate_arm cmd; + ) nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM, .nd_family = NVDIMM_FAMILY_INTEL, -- 2.43.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings 2025-06-25 21:42 [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva @ 2025-06-26 0:17 ` dan.j.williams 2025-06-26 1:03 ` dan.j.williams 2025-06-27 15:52 ` Kees Cook 2 siblings, 0 replies; 4+ messages in thread From: dan.j.williams @ 2025-06-26 0:17 UTC (permalink / raw) To: Gustavo A. R. Silva, Kees Cook, Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki, Len Brown Cc: nvdimm, linux-acpi, linux-kernel, Gustavo A. R. Silva, linux-hardening 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. > > Use the new TRAILING_OVERLAP() helper to 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] > > Acked-by: Dan Williams <dan.j.williams@intel.com> > Tested-by: Dan Williams <dan.j.williams@intel.com> Looks like our mails crossed [1], but I rushed this testing, apologies. This patch does cause a regression, and the conversion is not equivalent according to pahole: union pkg_nd_intel_bus_fw_activate { struct nd_cmd_pkg pkg; /* 0 64 */ struct { u8 _offset_to_fam[64]; /* 0 64 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct nd_intel_bus_fw_activate cmd; /* 64 5 */ } __attribute__((__packed__)); /* 0 69 */ }; struct pkg_nd_intel_bus_fw_activate2 { struct nd_cmd_pkg pkg; /* 0 64 */ /* XXX last struct has a flexible array */ /* --- cacheline 1 boundary (64 bytes) --- */ struct nd_intel_bus_fw_activate cmd; /* 64 5 */ /* size: 72, cachelines: 2, members: 2 */ /* padding: 3 */ /* flexible array members: end: 1 */ /* last cacheline: 8 bytes */ }; Now, why the padding at the end matters for this test, I am still trying to figure that out. [1]: http://lore.kernel.org/685c772aa7cc1_23a2a10080@dwillia2-mobl4.notmuch ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings 2025-06-25 21:42 [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva 2025-06-26 0:17 ` dan.j.williams @ 2025-06-26 1:03 ` dan.j.williams 2025-06-27 15:52 ` Kees Cook 2 siblings, 0 replies; 4+ messages in thread From: dan.j.williams @ 2025-06-26 1:03 UTC (permalink / raw) To: Gustavo A. R. Silva, Kees Cook, Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki, Len Brown Cc: nvdimm, linux-acpi, linux-kernel, Gustavo A. R. Silva, linux-hardening 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. > > Use the new TRAILING_OVERLAP() helper to 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] > > Acked-by: Dan Williams <dan.j.williams@intel.com> > Tested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > This patch should go through: > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/ (for-next/hardening) > > Changes in v4: > - Use the new TRAILING_OVERLAP() helper. > > Changes in v3: > - Use union instead of DEFINE_RAW_FLEX(). > - Link: https://lore.kernel.org/linux-hardening/aEneid7gdAZr1_kR@kspp/ > > Changes in v2: > - Use DEFINE_RAW_FLEX() instead of __struct_group(). > - Link: https://lore.kernel.org/linux-hardening/Z-QpUcxFCRByYcTA@kspp/ > > v1: > - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/ > > drivers/acpi/nfit/intel.c | 84 +++++++++++++++++---------------------- > 1 file changed, 36 insertions(+), 48 deletions(-) > > diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c > index 3902759abcba..d0b72e906428 100644 > --- a/drivers/acpi/nfit/intel.c > +++ b/drivers/acpi/nfit/intel.c > @@ -55,10 +55,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm, > { > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > unsigned long security_flags = 0; > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_get_security_state cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_get_security_state cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -120,10 +119,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm, > static int intel_security_freeze(struct nvdimm *nvdimm) > { > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_freeze_lock cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_freeze_lock cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_FREEZE_LOCK, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -153,10 +151,9 @@ static int intel_security_change_key(struct nvdimm *nvdimm, > unsigned int cmd = ptype == NVDIMM_MASTER ? > NVDIMM_INTEL_SET_MASTER_PASSPHRASE : > NVDIMM_INTEL_SET_PASSPHRASE; > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_set_passphrase cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_set_passphrase cmd; > + ) nd_cmd = { > .pkg = { > .nd_family = NVDIMM_FAMILY_INTEL, > .nd_size_in = ND_INTEL_PASSPHRASE_SIZE * 2, > @@ -195,10 +192,9 @@ static int __maybe_unused intel_security_unlock(struct nvdimm *nvdimm, > const struct nvdimm_key_data *key_data) > { > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_unlock_unit cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_unlock_unit cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_UNLOCK_UNIT, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -234,10 +230,9 @@ static int intel_security_disable(struct nvdimm *nvdimm, > { > int rc; > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_disable_passphrase cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_disable_passphrase cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_DISABLE_PASSPHRASE, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -277,10 +272,9 @@ static int __maybe_unused intel_security_erase(struct nvdimm *nvdimm, > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > unsigned int cmd = ptype == NVDIMM_MASTER ? > NVDIMM_INTEL_MASTER_SECURE_ERASE : NVDIMM_INTEL_SECURE_ERASE; > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_secure_erase cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_secure_erase cmd; > + ) nd_cmd = { > .pkg = { > .nd_family = NVDIMM_FAMILY_INTEL, > .nd_size_in = ND_INTEL_PASSPHRASE_SIZE, > @@ -318,10 +312,9 @@ static int __maybe_unused intel_security_query_overwrite(struct nvdimm *nvdimm) > { > int rc; > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_query_overwrite cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_query_overwrite cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_QUERY_OVERWRITE, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -354,10 +347,9 @@ static int __maybe_unused intel_security_overwrite(struct nvdimm *nvdimm, > { > int rc; > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_overwrite cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_overwrite cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_OVERWRITE, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -407,10 +399,9 @@ const struct nvdimm_security_ops *intel_security_ops = &__intel_security_ops; > static int intel_bus_fwa_businfo(struct nvdimm_bus_descriptor *nd_desc, > struct nd_intel_bus_fw_activate_businfo *info) > { > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_bus_fw_activate_businfo cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_bus_fw_activate_businfo cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, > .nd_family = NVDIMM_BUS_FAMILY_INTEL, > @@ -518,10 +509,9 @@ static enum nvdimm_fwa_capability intel_bus_fwa_capability( > static int intel_bus_fwa_activate(struct nvdimm_bus_descriptor *nd_desc) > { > struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_bus_fw_activate cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_bus_fw_activate cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE, > .nd_family = NVDIMM_BUS_FAMILY_INTEL, > @@ -582,10 +572,9 @@ const struct nvdimm_bus_fw_ops *intel_bus_fw_ops = &__intel_bus_fw_ops; > static int intel_fwa_dimminfo(struct nvdimm *nvdimm, > struct nd_intel_fw_activate_dimminfo *info) > { > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_fw_activate_dimminfo cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_fw_activate_dimminfo cmd; > + ) nd_cmd = { > .pkg = { > .nd_command = NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO, > .nd_family = NVDIMM_FAMILY_INTEL, > @@ -688,10 +677,9 @@ static int intel_fwa_arm(struct nvdimm *nvdimm, enum nvdimm_fwa_trigger arm) > { > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > struct acpi_nfit_desc *acpi_desc = nfit_mem->acpi_desc; > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_fw_activate_arm cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_fw_activate_arm cmd; > + ) nd_cmd = { The regression is here. > .pkg = { > .nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM, > .nd_family = NVDIMM_FAMILY_INTEL, So the full context is this: union { struct nd_cmd_pkg pkg; struct { u8 _offset_to_fam[offsetof(struct nd_cmd_pkg, nd_payload)]; struct nd_intel_fw_activate_arm cmd; }; } nd_cmd = { .pkg = { .nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM, .nd_family = NVDIMM_FAMILY_INTEL, .nd_size_in = sizeof(nd_cmd.cmd.activate_arm), .nd_size_out = sizeof(struct nd_intel_fw_activate_arm), .nd_fw_size = sizeof(struct nd_intel_fw_activate_arm), }, .cmd = { .activate_arm = arm == NVDIMM_FWA_ARM ? ND_INTEL_DIMM_FWA_ARM : ND_INTEL_DIMM_FWA_DISARM, }, }; The problem is that the designated initialization of .cmd zeroes out the .pkg portion of the union. This incremental change works, and with it folded you can keep my Acked-by and Tested-by on v5. You might want to remind folks about this designated initializer trap in the kdoc for TRAILING_OVERLAP(). -- 8< -- diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c index c88647428715..c63284ce9a87 100644 --- a/drivers/acpi/nfit/intel.c +++ b/drivers/acpi/nfit/intel.c @@ -511,29 +511,27 @@ static int intel_bus_fwa_activate(struct nvdimm_bus_descriptor *nd_desc) struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, struct nd_intel_bus_fw_activate cmd; - ) nd_cmd = { - .pkg = { - .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE, - .nd_family = NVDIMM_BUS_FAMILY_INTEL, - .nd_size_in = sizeof(nd_cmd.cmd.iodev_state), - .nd_size_out = - sizeof(struct nd_intel_bus_fw_activate), - .nd_fw_size = - sizeof(struct nd_intel_bus_fw_activate), - }, + ) nd_cmd; + int rc; + + nd_cmd.pkg = (struct nd_cmd_pkg) { + .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE, + .nd_family = NVDIMM_BUS_FAMILY_INTEL, + .nd_size_in = sizeof(nd_cmd.cmd.iodev_state), + .nd_size_out = sizeof(struct nd_intel_bus_fw_activate), + .nd_fw_size = sizeof(struct nd_intel_bus_fw_activate), + }; + nd_cmd.cmd = (struct nd_intel_bus_fw_activate) { /* * Even though activate is run from a suspended context, * for safety, still ask platform firmware to force * quiesce devices by default. Let a module * parameter override that policy. */ - .cmd = { - .iodev_state = acpi_desc->fwa_noidle - ? ND_INTEL_BUS_FWA_IODEV_OS_IDLE - : ND_INTEL_BUS_FWA_IODEV_FORCE_IDLE, - }, + .iodev_state = acpi_desc->fwa_noidle ? + ND_INTEL_BUS_FWA_IODEV_OS_IDLE : + ND_INTEL_BUS_FWA_IODEV_FORCE_IDLE, }; - int rc; switch (intel_bus_fwa_state(nd_desc)) { case NVDIMM_FWA_ARMED: @@ -679,24 +677,22 @@ static int intel_fwa_arm(struct nvdimm *nvdimm, enum nvdimm_fwa_trigger arm) struct acpi_nfit_desc *acpi_desc = nfit_mem->acpi_desc; TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, struct nd_intel_fw_activate_arm cmd; - ) nd_cmd = { - .pkg = { - .nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM, - .nd_family = NVDIMM_FAMILY_INTEL, - .nd_size_in = sizeof(nd_cmd.cmd.activate_arm), - .nd_size_out = - sizeof(struct nd_intel_fw_activate_arm), - .nd_fw_size = - sizeof(struct nd_intel_fw_activate_arm), - }, - .cmd = { - .activate_arm = arm == NVDIMM_FWA_ARM - ? ND_INTEL_DIMM_FWA_ARM - : ND_INTEL_DIMM_FWA_DISARM, - }, - }; + ) nd_cmd; int rc; + nd_cmd.pkg = (struct nd_cmd_pkg) { + .nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM, + .nd_family = NVDIMM_FAMILY_INTEL, + .nd_size_in = sizeof(nd_cmd.cmd.activate_arm), + .nd_size_out = sizeof(struct nd_intel_fw_activate_arm), + .nd_fw_size = sizeof(struct nd_intel_fw_activate_arm), + }; + nd_cmd.cmd = (struct nd_intel_fw_activate_arm) { + .activate_arm = arm == NVDIMM_FWA_ARM ? + ND_INTEL_DIMM_FWA_ARM : + ND_INTEL_DIMM_FWA_DISARM, + }; + switch (intel_fwa_state(nvdimm)) { case NVDIMM_FWA_INVALID: return -ENXIO; ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings 2025-06-25 21:42 [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva 2025-06-26 0:17 ` dan.j.williams 2025-06-26 1:03 ` dan.j.williams @ 2025-06-27 15:52 ` Kees Cook 2 siblings, 0 replies; 4+ messages in thread From: Kees Cook @ 2025-06-27 15:52 UTC (permalink / raw) To: Gustavo A. R. Silva Cc: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki, Len Brown, nvdimm, linux-acpi, linux-kernel, linux-hardening On Wed, Jun 25, 2025 at 03:42:16PM -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. > > Use the new TRAILING_OVERLAP() helper to 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] > > Acked-by: Dan Williams <dan.j.williams@intel.com> > Tested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > This patch should go through: > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/ (for-next/hardening) > > Changes in v4: > - Use the new TRAILING_OVERLAP() helper. > > Changes in v3: > - Use union instead of DEFINE_RAW_FLEX(). > - Link: https://lore.kernel.org/linux-hardening/aEneid7gdAZr1_kR@kspp/ > > Changes in v2: > - Use DEFINE_RAW_FLEX() instead of __struct_group(). > - Link: https://lore.kernel.org/linux-hardening/Z-QpUcxFCRByYcTA@kspp/ > > v1: > - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/ > > drivers/acpi/nfit/intel.c | 84 +++++++++++++++++---------------------- > 1 file changed, 36 insertions(+), 48 deletions(-) > > diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c > index 3902759abcba..d0b72e906428 100644 > --- a/drivers/acpi/nfit/intel.c > +++ b/drivers/acpi/nfit/intel.c > @@ -55,10 +55,9 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm, > { > struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); > unsigned long security_flags = 0; > - struct { > - struct nd_cmd_pkg pkg; > - struct nd_intel_get_security_state cmd; > - } nd_cmd = { > + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, > + struct nd_intel_get_security_state cmd; > + ) nd_cmd = { If you wanted, these could be even further minimized to this, leaving the trailing object indentation unchanged: - struct { - struct nd_cmd_pkg pkg; + TRAILING_OVERLAP(struct nd_cmd_pkg, pkg, nd_payload, struct nd_intel_get_security_state cmd; - } nd_cmd = { + ) nd_cmd = { -- Kees Cook ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-27 15:52 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-06-25 21:42 [PATCH v4][for-next/hardening] acpi: nfit: intel: avoid multiple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva 2025-06-26 0:17 ` dan.j.williams 2025-06-26 1:03 ` dan.j.williams 2025-06-27 15:52 ` Kees Cook
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).