* [PATCH][next] power: supply: cros_charge-control: Avoid -Wflex-array-member-not-at-end warning
@ 2025-04-29 19:20 Gustavo A. R. Silva
2025-04-29 19:25 ` Thomas Weißschuh
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-29 19:20 UTC (permalink / raw)
To: Thomas Weißschuh, Benson Leung, Guenter Roeck,
Sebastian Reichel
Cc: chrome-platform, linux-pm, 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 `DEFINE_RAW_FLEX()` helper for an on-stack definition 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 the following warning:
drivers/power/supply/cros_charge-control.c:57:40: 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>
---
drivers/power/supply/cros_charge-control.c | 26 +++++++++-------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
index 02d5bdbe2e8d..e33bc4c55bcc 100644
--- a/drivers/power/supply/cros_charge-control.c
+++ b/drivers/power/supply/cros_charge-control.c
@@ -53,23 +53,17 @@ static int cros_chctl_send_charge_control_cmd(struct cros_ec_device *cros_ec,
[3] = sizeof(struct ec_params_charge_control),
};
- struct {
- struct cros_ec_command msg;
- union {
- struct ec_params_charge_control req;
- struct ec_response_charge_control resp;
- } __packed data;
- } __packed buf = {
- .msg = {
- .command = EC_CMD_CHARGE_CONTROL,
- .version = cmd_version,
- .insize = 0,
- .outsize = outsizes[cmd_version],
- },
- .data.req = *req,
- };
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ MAX(sizeof(struct ec_params_charge_control),
+ sizeof(struct ec_response_charge_control)));
+
+ msg->command = EC_CMD_CHARGE_CONTROL;
+ msg->version = cmd_version;
+ msg->insize = 0;
+ msg->outsize = outsizes[cmd_version];
+ *(struct ec_params_charge_control *)msg->data = *req;
- return cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
+ return cros_ec_cmd_xfer_status(cros_ec, msg);
}
static int cros_chctl_configure_ec(struct cros_chctl_priv *priv)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH][next] power: supply: cros_charge-control: Avoid -Wflex-array-member-not-at-end warning
2025-04-29 19:20 [PATCH][next] power: supply: cros_charge-control: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-04-29 19:25 ` Thomas Weißschuh
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Weißschuh @ 2025-04-29 19:25 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Benson Leung, Guenter Roeck, Sebastian Reichel, chrome-platform,
linux-pm, linux-kernel, linux-hardening
On 2025-04-29 13:20:51-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 `DEFINE_RAW_FLEX()` helper for an on-stack definition 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 the following warning:
>
> drivers/power/supply/cros_charge-control.c:57:40: 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>
> ---
> drivers/power/supply/cros_charge-control.c | 26 +++++++++-------------
> 1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
> index 02d5bdbe2e8d..e33bc4c55bcc 100644
> --- a/drivers/power/supply/cros_charge-control.c
> +++ b/drivers/power/supply/cros_charge-control.c
> @@ -53,23 +53,17 @@ static int cros_chctl_send_charge_control_cmd(struct cros_ec_device *cros_ec,
> [3] = sizeof(struct ec_params_charge_control),
> };
>
> - struct {
> - struct cros_ec_command msg;
> - union {
> - struct ec_params_charge_control req;
> - struct ec_response_charge_control resp;
> - } __packed data;
> - } __packed buf = {
> - .msg = {
> - .command = EC_CMD_CHARGE_CONTROL,
> - .version = cmd_version,
> - .insize = 0,
> - .outsize = outsizes[cmd_version],
> - },
> - .data.req = *req,
> - };
> + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> + MAX(sizeof(struct ec_params_charge_control),
> + sizeof(struct ec_response_charge_control)));
> +
> + msg->command = EC_CMD_CHARGE_CONTROL;
> + msg->version = cmd_version;
> + msg->insize = 0;
> + msg->outsize = outsizes[cmd_version];
> + *(struct ec_params_charge_control *)msg->data = *req;
Please use cros_ec_cmd() like the LED driver.
https://lore.kernel.org/lkml/Z-rKcgFjsyKvd58q@kspp/
>
> - return cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
> + return cros_ec_cmd_xfer_status(cros_ec, msg);
> }
>
> static int cros_chctl_configure_ec(struct cros_chctl_priv *priv)
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-29 19:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 19:20 [PATCH][next] power: supply: cros_charge-control: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-04-29 19:25 ` Thomas Weißschuh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox