* [PATCH][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
@ 2025-03-26 22:35 Gustavo A. R. Silva
2025-03-27 6:27 ` Tzung-Bi Shih
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2025-03-26 22:35 UTC (permalink / raw)
To: Lukasz Majczak, Wim Van Sebroeck, Guenter Roeck, Benson Leung
Cc: chrome-platform, linux-watchdog, 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:
rivers/watchdog/cros_ec_wdt.c:29: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/watchdog/cros_ec_wdt.c | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
index 716c23f4388c..f6dba17d1036 100644
--- a/drivers/watchdog/cros_ec_wdt.c
+++ b/drivers/watchdog/cros_ec_wdt.c
@@ -25,26 +25,22 @@ static int cros_ec_wdt_send_cmd(struct cros_ec_device *cros_ec,
union cros_ec_wdt_data *arg)
{
int ret;
- struct {
- struct cros_ec_command msg;
- union cros_ec_wdt_data data;
- } __packed buf = {
- .msg = {
- .version = 0,
- .command = EC_CMD_HANG_DETECT,
- .insize = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
- sizeof(struct ec_response_hang_detect) :
- 0,
- .outsize = sizeof(struct ec_params_hang_detect),
- },
- .data.req = arg->req
- };
-
- ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
+ DEFINE_RAW_FLEX(struct cros_ec_command, buf, data,
+ sizeof(union cros_ec_wdt_data));
+
+ buf->version = 0;
+ buf->command = EC_CMD_HANG_DETECT;
+ buf->insize = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
+ sizeof(struct ec_response_hang_detect) :
+ 0;
+ buf->outsize = sizeof(struct ec_params_hang_detect);
+ ((union cros_ec_wdt_data *)buf->data)->req = arg->req;
+
+ ret = cros_ec_cmd_xfer_status(cros_ec, buf);
if (ret < 0)
return ret;
- arg->resp = buf.data.resp;
+ arg->resp = ((union cros_ec_wdt_data *)buf->data)->resp;
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
2025-03-26 22:35 [PATCH][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-03-27 6:27 ` Tzung-Bi Shih
0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2025-03-27 6:27 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Lukasz Majczak, Wim Van Sebroeck, Guenter Roeck, Benson Leung,
chrome-platform, linux-watchdog, linux-kernel, linux-hardening
On Wed, Mar 26, 2025 at 04:35:13PM -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:
>
> rivers/watchdog/cros_ec_wdt.c:29:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
^
d truncated.
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
With minor comments,
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
> + DEFINE_RAW_FLEX(struct cros_ec_command, buf, data,
> + sizeof(union cros_ec_wdt_data));
s/buf/msg/g makes much sense.
> + ((union cros_ec_wdt_data *)buf->data)->req = arg->req;
Or,
*(struct ec_params_hang_detect *)buf->data = arg->req;
> - arg->resp = buf.data.resp;
> + arg->resp = ((union cros_ec_wdt_data *)buf->data)->resp;
Or,
arg->resp = *(struct ec_response_hang_detect *)buf->data;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-27 6:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 22:35 [PATCH][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-03-27 6:27 ` Tzung-Bi Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox