From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Benson Leung <bleung@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
Guenter Roeck <groeck@chromium.org>
Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH][next] platform/chrome: cros_ec: Avoid -Wflex-array-member-not-at-end warning
Date: Fri, 28 Mar 2025 07:50:11 -0600 [thread overview]
Message-ID: <Z-apE0ZmckBjRDyx@kspp> (raw)
-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/platform/chrome/cros_ec.c:106: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/platform/chrome/cros_ec.c | 47 +++++++++++++++++--------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index 110771a8645e..cd15aa0cb082 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -99,51 +99,56 @@ irqreturn_t cros_ec_irq_thread(int irq, void *data)
}
EXPORT_SYMBOL(cros_ec_irq_thread);
+union cros_ec_sleep_data {
+ struct ec_params_host_sleep_event req0;
+ struct ec_params_host_sleep_event_v1 req1;
+ struct ec_response_host_sleep_event_v1 resp1;
+} __packed;
+
static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)
{
int ret;
- struct {
- struct cros_ec_command msg;
- union {
- struct ec_params_host_sleep_event req0;
- struct ec_params_host_sleep_event_v1 req1;
- struct ec_response_host_sleep_event_v1 resp1;
- } u;
- } __packed buf;
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ sizeof(union cros_ec_sleep_data));
+ struct ec_params_host_sleep_event *req0 =
+ (struct ec_params_host_sleep_event *)msg->data;
+ struct ec_params_host_sleep_event_v1 *req1 =
+ (struct ec_params_host_sleep_event_v1 *)msg->data;
+ struct ec_response_host_sleep_event_v1 *resp1 =
+ (struct ec_response_host_sleep_event_v1 *)msg->data;
- memset(&buf, 0, sizeof(buf));
if (ec_dev->host_sleep_v1) {
- buf.u.req1.sleep_event = sleep_event;
- buf.u.req1.suspend_params.sleep_timeout_ms =
+ req1->sleep_event = sleep_event;
+ req1->suspend_params.sleep_timeout_ms =
ec_dev->suspend_timeout_ms;
- buf.msg.outsize = sizeof(buf.u.req1);
+ msg->outsize = sizeof(*req1);
if ((sleep_event == HOST_SLEEP_EVENT_S3_RESUME) ||
(sleep_event == HOST_SLEEP_EVENT_S0IX_RESUME))
- buf.msg.insize = sizeof(buf.u.resp1);
+ msg->insize = sizeof(*resp1);
- buf.msg.version = 1;
+ msg->version = 1;
} else {
- buf.u.req0.sleep_event = sleep_event;
- buf.msg.outsize = sizeof(buf.u.req0);
+ req0->sleep_event = sleep_event;
+ msg->outsize = sizeof(*req0);
}
- buf.msg.command = EC_CMD_HOST_SLEEP_EVENT;
+ msg->command = EC_CMD_HOST_SLEEP_EVENT;
- ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg);
+ ret = cros_ec_cmd_xfer_status(ec_dev, msg);
/* Report failure to transition to system wide suspend with a warning. */
if (ret >= 0 && ec_dev->host_sleep_v1 &&
(sleep_event == HOST_SLEEP_EVENT_S0IX_RESUME ||
sleep_event == HOST_SLEEP_EVENT_S3_RESUME)) {
ec_dev->last_resume_result =
- buf.u.resp1.resume_response.sleep_transitions;
+ resp1->resume_response.sleep_transitions;
- WARN_ONCE(buf.u.resp1.resume_response.sleep_transitions &
+ WARN_ONCE(resp1->resume_response.sleep_transitions &
EC_HOST_RESUME_SLEEP_TIMEOUT,
"EC detected sleep transition timeout. Total sleep transitions: %d",
- buf.u.resp1.resume_response.sleep_transitions &
+ resp1->resume_response.sleep_transitions &
EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK);
}
--
2.43.0
next reply other threads:[~2025-03-28 13:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 13:50 Gustavo A. R. Silva [this message]
2025-04-01 10:17 ` [PATCH][next] platform/chrome: cros_ec: Avoid -Wflex-array-member-not-at-end warning Tzung-Bi Shih
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z-apE0ZmckBjRDyx@kspp \
--to=gustavoars@kernel.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=groeck@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tzungbi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox