lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z-apE0ZmckBjRDyx@kspp>
Date: Fri, 28 Mar 2025 07:50:11 -0600
From: "Gustavo A. R. Silva" <gustavoars@...nel.org>
To: Benson Leung <bleung@...omium.org>, Tzung-Bi Shih <tzungbi@...nel.org>,
	Guenter Roeck <groeck@...omium.org>
Cc: chrome-platform@...ts.linux.dev, linux-kernel@...r.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@...nel.org>,
	linux-hardening@...r.kernel.org
Subject: [PATCH][next] platform/chrome: cros_ec: Avoid
 -Wflex-array-member-not-at-end warning

-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@...nel.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ