Skip to contentSkip to conversation

power: supply: cros_charge-control: Avoid -Wflex-array-member-not-at-end warning

PATCH Superseded Gustavo A. R. Silva 2 participants 2 messages Apr 29, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: cros_charge-control: 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/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]

---
 drivers/power/supply/cros_charge-control.c | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/power/supply/cros_charge-control.c +10 -16
index 02d5bdbe2e8d..e33bc4c55bcc 100644
@@ -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)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 39 lines · Gustavo A. R. Silva

-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]

---
 drivers/power/supply/cros_charge-control.c | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/power/supply/cros_charge-control.c +0 -14
index 02d5bdbe2e8d..e33bc4c55bcc 100644
@@ -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,

drivers/power/supply/cros_charge-control.c static int cros_chctl_send_charge_control_cmd(struct cros_ec_device *cros_ec, · line 64

Quoted 10 lines
drivers/power/supply/cros_charge-control.c +9 -1
-	};
+	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/

Quoted 9 lines
drivers/power/supply/cros_charge-control.c +1 -1
-	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)
Signature · 1 line
2.43.0