drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++-------------------- 1 file changed, 179 insertions(+), 209 deletions(-)
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.
Use the `DEFINE_RAW_FLEX()` helper for on-stack definitions of
a flexible structure where the size of the flexible-array member
is known at compile-time, and refactor the rest of the code,
accordingly.
So, with these changes, fix a dozen of the following warnings:
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 v2:
- Use DEFINE_RAW_FLEX() instead of __struct_group().
v1:
- Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/
drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++--------------------
1 file changed, 179 insertions(+), 209 deletions(-)
diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
index 3902759abcba..114d5b3bb39b 100644
--- a/drivers/acpi/nfit/intel.c
+++ b/drivers/acpi/nfit/intel.c
@@ -55,21 +55,17 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_out =
- sizeof(struct nd_intel_get_security_state),
- .nd_fw_size =
- sizeof(struct nd_intel_get_security_state),
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_get_security_state));
+ struct nd_intel_get_security_state *cmd =
+ (struct nd_intel_get_security_state *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_command = NVDIMM_INTEL_GET_SECURITY_STATE;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_out = sizeof(struct nd_intel_get_security_state);
+ nd_cmd->nd_fw_size = sizeof(struct nd_intel_get_security_state);
+
if (!test_bit(NVDIMM_INTEL_GET_SECURITY_STATE, &nfit_mem->dsm_mask))
return 0;
@@ -81,33 +77,34 @@ static unsigned long intel_security_flags(struct nvdimm *nvdimm,
if (nvdimm_in_overwrite(nvdimm) && ptype == NVDIMM_USER)
return BIT(NVDIMM_SECURITY_OVERWRITE);
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
- if (rc < 0 || nd_cmd.cmd.status) {
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
+ if (rc < 0 || cmd->status) {
pr_err("%s: security state retrieval failed (%d:%#x)\n",
- nvdimm_name(nvdimm), rc, nd_cmd.cmd.status);
+ nvdimm_name(nvdimm), rc, cmd->status);
return 0;
}
/* check and see if security is enabled and locked */
if (ptype == NVDIMM_MASTER) {
- if (nd_cmd.cmd.extended_state & ND_INTEL_SEC_ESTATE_ENABLED)
+ if (cmd->extended_state & ND_INTEL_SEC_ESTATE_ENABLED)
set_bit(NVDIMM_SECURITY_UNLOCKED, &security_flags);
else
set_bit(NVDIMM_SECURITY_DISABLED, &security_flags);
- if (nd_cmd.cmd.extended_state & ND_INTEL_SEC_ESTATE_PLIMIT)
+ if (cmd->extended_state & ND_INTEL_SEC_ESTATE_PLIMIT)
set_bit(NVDIMM_SECURITY_FROZEN, &security_flags);
return security_flags;
}
- if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_UNSUPPORTED)
+ if (cmd->state & ND_INTEL_SEC_STATE_UNSUPPORTED)
return 0;
- if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_ENABLED) {
- if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_FROZEN ||
- nd_cmd.cmd.state & ND_INTEL_SEC_STATE_PLIMIT)
+ if (cmd->state & ND_INTEL_SEC_STATE_ENABLED) {
+ if (cmd->state & ND_INTEL_SEC_STATE_FROZEN ||
+ cmd->state & ND_INTEL_SEC_STATE_PLIMIT)
set_bit(NVDIMM_SECURITY_FROZEN, &security_flags);
- if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_LOCKED)
+ if (cmd->state & ND_INTEL_SEC_STATE_LOCKED)
set_bit(NVDIMM_SECURITY_LOCKED, &security_flags);
else
set_bit(NVDIMM_SECURITY_UNLOCKED, &security_flags);
@@ -120,26 +117,25 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_FREEZE_LOCK,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_freeze_lock));
+ struct nd_intel_freeze_lock *cmd =
+ (struct nd_intel_freeze_lock *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_command = NVDIMM_INTEL_FREEZE_LOCK;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
+
if (!test_bit(NVDIMM_INTEL_FREEZE_LOCK, &nfit_mem->dsm_mask))
return -ENOTTY;
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- if (nd_cmd.cmd.status)
+ if (cmd->status)
return -EIO;
return 0;
}
@@ -153,32 +149,31 @@ 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 = {
- .pkg = {
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_in = ND_INTEL_PASSPHRASE_SIZE * 2,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- .nd_command = cmd,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_set_passphrase));
+ struct nd_intel_set_passphrase *cmd_pp =
+ (struct nd_intel_set_passphrase *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = ND_INTEL_PASSPHRASE_SIZE * 2;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_command = cmd;
+
if (!test_bit(cmd, &nfit_mem->dsm_mask))
return -ENOTTY;
- memcpy(nd_cmd.cmd.old_pass, old_data->data,
- sizeof(nd_cmd.cmd.old_pass));
- memcpy(nd_cmd.cmd.new_pass, new_data->data,
- sizeof(nd_cmd.cmd.new_pass));
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ memcpy(cmd_pp->old_pass, old_data->data,
+ sizeof(cmd_pp->old_pass));
+ memcpy(cmd_pp->new_pass, new_data->data,
+ sizeof(cmd_pp->new_pass));
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd_pp->status) {
case 0:
return 0;
case ND_INTEL_STATUS_INVALID_PASS:
@@ -195,29 +190,28 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_UNLOCK_UNIT,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_in = ND_INTEL_PASSPHRASE_SIZE,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_unlock_unit));
+ struct nd_intel_unlock_unit *cmd =
+ (struct nd_intel_unlock_unit *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_command = NVDIMM_INTEL_UNLOCK_UNIT;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = ND_INTEL_PASSPHRASE_SIZE;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
+
if (!test_bit(NVDIMM_INTEL_UNLOCK_UNIT, &nfit_mem->dsm_mask))
return -ENOTTY;
- memcpy(nd_cmd.cmd.passphrase, key_data->data,
- sizeof(nd_cmd.cmd.passphrase));
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ memcpy(cmd->passphrase, key_data->data,
+ sizeof(cmd->passphrase));
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd->status) {
case 0:
break;
case ND_INTEL_STATUS_INVALID_PASS:
@@ -234,29 +228,28 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_DISABLE_PASSPHRASE,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_in = ND_INTEL_PASSPHRASE_SIZE,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_disable_passphrase));
+ struct nd_intel_disable_passphrase *cmd =
+ (struct nd_intel_disable_passphrase *)nd_cmd->nd_payload;
+
+ nd_cmd->nd_command = NVDIMM_INTEL_DISABLE_PASSPHRASE;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = ND_INTEL_PASSPHRASE_SIZE;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
if (!test_bit(NVDIMM_INTEL_DISABLE_PASSPHRASE, &nfit_mem->dsm_mask))
return -ENOTTY;
- memcpy(nd_cmd.cmd.passphrase, key_data->data,
- sizeof(nd_cmd.cmd.passphrase));
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ memcpy(cmd->passphrase, key_data->data,
+ sizeof(cmd->passphrase));
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd->status) {
case 0:
break;
case ND_INTEL_STATUS_INVALID_PASS:
@@ -277,29 +270,28 @@ 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 = {
- .pkg = {
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_in = ND_INTEL_PASSPHRASE_SIZE,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- .nd_command = cmd,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_secure_erase));
+ struct nd_intel_secure_erase *cmd_se =
+ (struct nd_intel_secure_erase *)nd_cmd->nd_payload;
+
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = ND_INTEL_PASSPHRASE_SIZE;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_command = cmd;
if (!test_bit(cmd, &nfit_mem->dsm_mask))
return -ENOTTY;
- memcpy(nd_cmd.cmd.passphrase, key->data,
- sizeof(nd_cmd.cmd.passphrase));
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ memcpy(cmd_se->passphrase, key->data,
+ sizeof(cmd_se->passphrase));
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd_se->status) {
case 0:
break;
case ND_INTEL_STATUS_NOT_SUPPORTED:
@@ -318,26 +310,25 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_QUERY_OVERWRITE,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_query_overwrite));
+ struct nd_intel_query_overwrite *cmd =
+ (struct nd_intel_query_overwrite *)nd_cmd->nd_payload;
+
+ nd_cmd->nd_command = NVDIMM_INTEL_QUERY_OVERWRITE;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
if (!test_bit(NVDIMM_INTEL_QUERY_OVERWRITE, &nfit_mem->dsm_mask))
return -ENOTTY;
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd->status) {
case 0:
break;
case ND_INTEL_STATUS_OQUERY_INPROGRESS:
@@ -354,29 +345,28 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_OVERWRITE,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_in = ND_INTEL_PASSPHRASE_SIZE,
- .nd_size_out = ND_INTEL_STATUS_SIZE,
- .nd_fw_size = ND_INTEL_STATUS_SIZE,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_overwrite));
+ struct nd_intel_overwrite *cmd =
+ (struct nd_intel_overwrite *)nd_cmd->nd_payload;
+
+ nd_cmd->nd_command = NVDIMM_INTEL_OVERWRITE;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = ND_INTEL_PASSPHRASE_SIZE;
+ nd_cmd->nd_size_out = ND_INTEL_STATUS_SIZE;
+ nd_cmd->nd_fw_size = ND_INTEL_STATUS_SIZE;
if (!test_bit(NVDIMM_INTEL_OVERWRITE, &nfit_mem->dsm_mask))
return -ENOTTY;
- memcpy(nd_cmd.cmd.passphrase, nkey->data,
- sizeof(nd_cmd.cmd.passphrase));
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ memcpy(cmd->passphrase, nkey->data,
+ sizeof(cmd->passphrase));
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
if (rc < 0)
return rc;
- switch (nd_cmd.cmd.status) {
+ switch (cmd->status) {
case 0:
return 0;
case ND_INTEL_STATUS_OVERWRITE_UNSUPPORTED:
@@ -407,24 +397,18 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO,
- .nd_family = NVDIMM_BUS_FAMILY_INTEL,
- .nd_size_out =
- sizeof(struct nd_intel_bus_fw_activate_businfo),
- .nd_fw_size =
- sizeof(struct nd_intel_bus_fw_activate_businfo),
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_bus_fw_activate_businfo));
int rc;
- rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd),
- NULL);
- *info = nd_cmd.cmd;
+ nd_cmd->nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO;
+ nd_cmd->nd_family = NVDIMM_BUS_FAMILY_INTEL;
+ nd_cmd->nd_size_out = sizeof(struct nd_intel_bus_fw_activate_businfo);
+ nd_cmd->nd_fw_size = sizeof(struct nd_intel_bus_fw_activate_businfo);
+
+ rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CALL, nd_cmd,
+ __struct_size(nd_cmd), NULL);
+ *info = *(struct nd_intel_bus_fw_activate_businfo *)nd_cmd->nd_payload;
return rc;
}
@@ -518,33 +502,28 @@ 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 = {
- .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),
- },
- /*
- * 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,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_bus_fw_activate));
+ struct nd_intel_bus_fw_activate *cmd =
+ (struct nd_intel_bus_fw_activate *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE;
+ nd_cmd->nd_family = NVDIMM_BUS_FAMILY_INTEL;
+ nd_cmd->nd_size_in = sizeof(cmd->iodev_state);
+ nd_cmd->nd_size_out = sizeof(struct nd_intel_bus_fw_activate);
+ nd_cmd->nd_fw_size = sizeof(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;
+
switch (intel_bus_fwa_state(nd_desc)) {
case NVDIMM_FWA_ARMED:
case NVDIMM_FWA_ARM_OVERFLOW:
@@ -553,8 +532,8 @@ static int intel_bus_fwa_activate(struct nvdimm_bus_descriptor *nd_desc)
return -ENXIO;
}
- rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd),
- NULL);
+ rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CALL, nd_cmd,
+ __struct_size(nd_cmd), NULL);
/*
* Whether the command succeeded, or failed, the agent checking
@@ -582,23 +561,18 @@ 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 = {
- .pkg = {
- .nd_command = NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO,
- .nd_family = NVDIMM_FAMILY_INTEL,
- .nd_size_out =
- sizeof(struct nd_intel_fw_activate_dimminfo),
- .nd_fw_size =
- sizeof(struct nd_intel_fw_activate_dimminfo),
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_fw_activate_dimminfo));
int rc;
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
- *info = nd_cmd.cmd;
+ nd_cmd->nd_command = NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_out = sizeof(struct nd_intel_fw_activate_dimminfo);
+ nd_cmd->nd_fw_size = sizeof(struct nd_intel_fw_activate_dimminfo);
+
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
+ *info = *(struct nd_intel_fw_activate_dimminfo *)nd_cmd->nd_payload;
return rc;
}
@@ -688,27 +662,22 @@ 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 = {
- .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,
- },
- };
+ DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
+ sizeof(struct nd_intel_fw_activate_arm));
+ struct nd_intel_fw_activate_arm *cmd =
+ (struct nd_intel_fw_activate_arm *)nd_cmd->nd_payload;
int rc;
+ nd_cmd->nd_command = NVDIMM_INTEL_FW_ACTIVATE_ARM;
+ nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
+ nd_cmd->nd_size_in = sizeof(cmd->activate_arm);
+ nd_cmd->nd_size_out = sizeof(struct nd_intel_fw_activate_arm);
+ nd_cmd->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;
+
switch (intel_fwa_state(nvdimm)) {
case NVDIMM_FWA_INVALID:
return -ENXIO;
@@ -733,7 +702,8 @@ static int intel_fwa_arm(struct nvdimm *nvdimm, enum nvdimm_fwa_trigger arm)
acpi_desc->fwa_state = NVDIMM_FWA_INVALID;
nfit_mem->fwa_state = NVDIMM_FWA_INVALID;
- rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL);
+ rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, nd_cmd, __struct_size(nd_cmd),
+ NULL);
dev_dbg(acpi_desc->dev, "%s result: %d\n", arm == NVDIMM_FWA_ARM
? "arm" : "disarm", rc);
--
2.43.0
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 `DEFINE_RAW_FLEX()` helper for on-stack definitions of
> a flexible structure where the size of the flexible-array member
> is known at compile-time, and refactor the rest of the code,
> accordingly.
>
> So, with these changes, fix a dozen of the following warnings:
>
> 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 v2:
> - Use DEFINE_RAW_FLEX() instead of __struct_group().
>
> v1:
> - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/
>
> drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++--------------------
> 1 file changed, 179 insertions(+), 209 deletions(-)
>
> diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
> index 3902759abcba..114d5b3bb39b 100644
> --- a/drivers/acpi/nfit/intel.c
> +++ b/drivers/acpi/nfit/intel.c
> @@ -55,21 +55,17 @@ 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 = {
> - .pkg = {
> - .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> - .nd_family = NVDIMM_FAMILY_INTEL,
> - .nd_size_out =
> - sizeof(struct nd_intel_get_security_state),
> - .nd_fw_size =
> - sizeof(struct nd_intel_get_security_state),
> - },
> - };
> + DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> + sizeof(struct nd_intel_get_security_state));
> + struct nd_intel_get_security_state *cmd =
> + (struct nd_intel_get_security_state *)nd_cmd->nd_payload;
> int rc;
>
> + nd_cmd->nd_command = NVDIMM_INTEL_GET_SECURITY_STATE;
> + nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
> + nd_cmd->nd_size_out = sizeof(struct nd_intel_get_security_state);
> + nd_cmd->nd_fw_size = sizeof(struct nd_intel_get_security_state);
Can this keep the C99 init-style with something like (untested):
_DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
sizeof(struct nd_intel_get_security_state), {
.pkg = {
.nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
.nd_family = NVDIMM_FAMILY_INTEL,
.nd_size_out =
sizeof(struct nd_intel_get_security_state),
.nd_fw_size =
sizeof(struct nd_intel_get_security_state),
},
});
?
On 27/03/25 08:03, Dan Williams wrote:
> 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 `DEFINE_RAW_FLEX()` helper for on-stack definitions of
>> a flexible structure where the size of the flexible-array member
>> is known at compile-time, and refactor the rest of the code,
>> accordingly.
>>
>> So, with these changes, fix a dozen of the following warnings:
>>
>> 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 v2:
>> - Use DEFINE_RAW_FLEX() instead of __struct_group().
>>
>> v1:
>> - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/
>>
>> drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++--------------------
>> 1 file changed, 179 insertions(+), 209 deletions(-)
>>
>> diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
>> index 3902759abcba..114d5b3bb39b 100644
>> --- a/drivers/acpi/nfit/intel.c
>> +++ b/drivers/acpi/nfit/intel.c
>> @@ -55,21 +55,17 @@ 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 = {
>> - .pkg = {
>> - .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
>> - .nd_family = NVDIMM_FAMILY_INTEL,
>> - .nd_size_out =
>> - sizeof(struct nd_intel_get_security_state),
>> - .nd_fw_size =
>> - sizeof(struct nd_intel_get_security_state),
>> - },
>> - };
>> + DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
>> + sizeof(struct nd_intel_get_security_state));
>> + struct nd_intel_get_security_state *cmd =
>> + (struct nd_intel_get_security_state *)nd_cmd->nd_payload;
>> int rc;
>>
>> + nd_cmd->nd_command = NVDIMM_INTEL_GET_SECURITY_STATE;
>> + nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
>> + nd_cmd->nd_size_out = sizeof(struct nd_intel_get_security_state);
>> + nd_cmd->nd_fw_size = sizeof(struct nd_intel_get_security_state);
>
> Can this keep the C99 init-style with something like (untested):
>
> _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> sizeof(struct nd_intel_get_security_state), {
> .pkg = {
> .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> .nd_family = NVDIMM_FAMILY_INTEL,
> .nd_size_out =
> sizeof(struct nd_intel_get_security_state),
> .nd_fw_size =
> sizeof(struct nd_intel_get_security_state),
> },
> });
>
>
> ?
The code below works - however, notice that in this case we should
go through 'obj', which is an object defined in _DEFINE_FLEX().
_DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
sizeof(struct nd_intel_get_security_state), = {
.obj = {
.nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
.nd_family = NVDIMM_FAMILY_INTEL,
.nd_size_out =
sizeof(struct nd_intel_get_security_state),
.nd_fw_size =
sizeof(struct nd_intel_get_security_state),
},
});
Thanks
-Gustavo
On 30/04/25 13:41, Gustavo A. R. Silva wrote:
>
>
> On 27/03/25 08:03, Dan Williams wrote:
>> 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 `DEFINE_RAW_FLEX()` helper for on-stack definitions of
>>> a flexible structure where the size of the flexible-array member
>>> is known at compile-time, and refactor the rest of the code,
>>> accordingly.
>>>
>>> So, with these changes, fix a dozen of the following warnings:
>>>
>>> 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 v2:
>>> - Use DEFINE_RAW_FLEX() instead of __struct_group().
>>>
>>> v1:
>>> - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/
>>>
>>> drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++--------------------
>>> 1 file changed, 179 insertions(+), 209 deletions(-)
>>>
>>> diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
>>> index 3902759abcba..114d5b3bb39b 100644
>>> --- a/drivers/acpi/nfit/intel.c
>>> +++ b/drivers/acpi/nfit/intel.c
>>> @@ -55,21 +55,17 @@ 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 = {
>>> - .pkg = {
>>> - .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
>>> - .nd_family = NVDIMM_FAMILY_INTEL,
>>> - .nd_size_out =
>>> - sizeof(struct nd_intel_get_security_state),
>>> - .nd_fw_size =
>>> - sizeof(struct nd_intel_get_security_state),
>>> - },
>>> - };
>>> + DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
>>> + sizeof(struct nd_intel_get_security_state));
>>> + struct nd_intel_get_security_state *cmd =
>>> + (struct nd_intel_get_security_state *)nd_cmd->nd_payload;
>>> int rc;
>>> + nd_cmd->nd_command = NVDIMM_INTEL_GET_SECURITY_STATE;
>>> + nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
>>> + nd_cmd->nd_size_out = sizeof(struct nd_intel_get_security_state);
>>> + nd_cmd->nd_fw_size = sizeof(struct nd_intel_get_security_state);
>>
>> Can this keep the C99 init-style with something like (untested):
>>
>> _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
>> sizeof(struct nd_intel_get_security_state), {
>> .pkg = {
>> .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
>> .nd_family = NVDIMM_FAMILY_INTEL,
>> .nd_size_out =
>> sizeof(struct nd_intel_get_security_state),
>> .nd_fw_size =
>> sizeof(struct nd_intel_get_security_state),
>> },
>> });
>>
>>
>> ?
>
> The code below works - however, notice that in this case we should
> go through 'obj', which is an object defined in _DEFINE_FLEX().
>
> _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> sizeof(struct nd_intel_get_security_state), = {
> .obj = {
> .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> .nd_family = NVDIMM_FAMILY_INTEL,
> .nd_size_out =
> sizeof(struct nd_intel_get_security_state),
> .nd_fw_size =
> sizeof(struct nd_intel_get_security_state),
> },
> });
>
Now, I can modify the helper like this:
diff --git a/include/linux/overflow.h b/include/linux/overflow.h
index 69533e703be5..170d3cfe7ecc 100644
--- a/include/linux/overflow.h
+++ b/include/linux/overflow.h
@@ -404,7 +404,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
union { \
u8 bytes[struct_size_t(type, member, count)]; \
type obj; \
- } name##_u initializer; \
+ } name##_u = { .obj initializer }; \
type *name = (type *)&name##_u
/**
and then we can use the helper as follows:
_DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
sizeof(struct nd_intel_get_security_state), = {
.nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
.nd_family = NVDIMM_FAMILY_INTEL,
.nd_size_out =
sizeof(struct nd_intel_get_security_state),
.nd_fw_size =
sizeof(struct nd_intel_get_security_state),
});
OK, I'll go and update the helper.
-Gustavo
On Wed, Apr 30, 2025 at 02:07:24PM -0600, Gustavo A. R. Silva wrote:
>
>
> On 30/04/25 13:41, Gustavo A. R. Silva wrote:
> >
> >
> > On 27/03/25 08:03, Dan Williams wrote:
> > > 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 `DEFINE_RAW_FLEX()` helper for on-stack definitions of
> > > > a flexible structure where the size of the flexible-array member
> > > > is known at compile-time, and refactor the rest of the code,
> > > > accordingly.
> > > >
> > > > So, with these changes, fix a dozen of the following warnings:
> > > >
> > > > 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 v2:
> > > > - Use DEFINE_RAW_FLEX() instead of __struct_group().
> > > >
> > > > v1:
> > > > - Link: https://lore.kernel.org/linux-hardening/Z618ILbAR8YAvTkd@kspp/
> > > >
> > > > drivers/acpi/nfit/intel.c | 388 ++++++++++++++++++--------------------
> > > > 1 file changed, 179 insertions(+), 209 deletions(-)
> > > >
> > > > diff --git a/drivers/acpi/nfit/intel.c b/drivers/acpi/nfit/intel.c
> > > > index 3902759abcba..114d5b3bb39b 100644
> > > > --- a/drivers/acpi/nfit/intel.c
> > > > +++ b/drivers/acpi/nfit/intel.c
> > > > @@ -55,21 +55,17 @@ 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 = {
> > > > - .pkg = {
> > > > - .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> > > > - .nd_family = NVDIMM_FAMILY_INTEL,
> > > > - .nd_size_out =
> > > > - sizeof(struct nd_intel_get_security_state),
> > > > - .nd_fw_size =
> > > > - sizeof(struct nd_intel_get_security_state),
> > > > - },
> > > > - };
> > > > + DEFINE_RAW_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> > > > + sizeof(struct nd_intel_get_security_state));
> > > > + struct nd_intel_get_security_state *cmd =
> > > > + (struct nd_intel_get_security_state *)nd_cmd->nd_payload;
> > > > int rc;
> > > > + nd_cmd->nd_command = NVDIMM_INTEL_GET_SECURITY_STATE;
> > > > + nd_cmd->nd_family = NVDIMM_FAMILY_INTEL;
> > > > + nd_cmd->nd_size_out = sizeof(struct nd_intel_get_security_state);
> > > > + nd_cmd->nd_fw_size = sizeof(struct nd_intel_get_security_state);
> > >
> > > Can this keep the C99 init-style with something like (untested):
> > >
> > > _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> > > sizeof(struct nd_intel_get_security_state), {
> > > .pkg = {
> > > .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> > > .nd_family = NVDIMM_FAMILY_INTEL,
> > > .nd_size_out =
> > > sizeof(struct nd_intel_get_security_state),
> > > .nd_fw_size =
> > > sizeof(struct nd_intel_get_security_state),
> > > },
> > > });
> > >
> > >
> > > ?
> >
> > The code below works - however, notice that in this case we should
> > go through 'obj', which is an object defined in _DEFINE_FLEX().
> >
> > _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> > sizeof(struct nd_intel_get_security_state), = {
> > .obj = {
> > .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> > .nd_family = NVDIMM_FAMILY_INTEL,
> > .nd_size_out =
> > sizeof(struct nd_intel_get_security_state),
> > .nd_fw_size =
> > sizeof(struct nd_intel_get_security_state),
> > },
> > });
> >
>
> Now, I can modify the helper like this:
>
> diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> index 69533e703be5..170d3cfe7ecc 100644
> --- a/include/linux/overflow.h
> +++ b/include/linux/overflow.h
> @@ -404,7 +404,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
> union { \
> u8 bytes[struct_size_t(type, member, count)]; \
> type obj; \
> - } name##_u initializer; \
> + } name##_u = { .obj initializer }; \
> type *name = (type *)&name##_u
Ah yeah, nice. That could work!
I wish we could make it more idiomatic, but even if we pushed the
initializer to the end, we have to repeat the type...
#define _DEFINE_FLEX(type, name, member, count, initializer...) \
_Static_assert(__builtin_constant_p(count), \
"onstack flex array members require compile-time const count"); \
union { \
u8 bytes[struct_size_t(type, member, count)]; \
type obj; \
} name##_u = { }; \
type *name = (type *)&name##_u; \
*name
_DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
sizeof(struct nd_intel_get_security_state))
= (struct nd_cmd_pkg){
.nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
.nd_family = NVDIMM_FAMILY_INTEL,
.nd_size_out =
sizeof(struct nd_intel_get_security_state),
.nd_fw_size =
sizeof(struct nd_intel_get_security_state),
};
So, I think what you have is more readable (or perhaps less surprising),
even if a little "weird". :)
>
> /**
>
> and then we can use the helper as follows:
>
> _DEFINE_FLEX(struct nd_cmd_pkg, nd_cmd, nd_payload,
> sizeof(struct nd_intel_get_security_state), = {
> .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE,
> .nd_family = NVDIMM_FAMILY_INTEL,
> .nd_size_out =
> sizeof(struct nd_intel_get_security_state),
> .nd_fw_size =
> sizeof(struct nd_intel_get_security_state),
> });
>
> OK, I'll go and update the helper.
Sounds good!
-Kees
--
Kees Cook
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 `DEFINE_RAW_FLEX()` helper for on-stack definitions of > a flexible structure where the size of the flexible-array member > is known at compile-time, and refactor the rest of the code, > accordingly. > > So, with these changes, fix a dozen of the following warnings: > > 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> Reviewed-by: Ira Weiny <ira.weiny@intel.com> [snip]
© 2016 - 2025 Red Hat, Inc.