Skip to content

Commit da90147

Browse files
GustavoARSilvaTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_debugfs: Avoid -Wflex-array-member-not-at-end warnings
-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 warnings: drivers/platform/chrome/cros_ec_debugfs.c:211:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/platform/chrome/cros_ec_debugfs.c:257:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/platform/chrome/cros_ec_debugfs.c:279: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 <[email protected]> Link: https://lore.kernel.org/r/Z-aiAAcIP7sBRtz0@kspp Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 04251bc commit da90147

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

drivers/platform/chrome/cros_ec_debugfs.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,15 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
207207
char read_buf[EC_USB_PD_MAX_PORTS * 40], *p = read_buf;
208208
struct cros_ec_debugfs *debug_info = file->private_data;
209209
struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
210-
struct {
211-
struct cros_ec_command msg;
212-
union {
213-
struct ec_response_usb_pd_control_v1 resp;
214-
struct ec_params_usb_pd_control params;
215-
};
216-
} __packed ec_buf;
217-
struct cros_ec_command *msg;
218-
struct ec_response_usb_pd_control_v1 *resp;
219-
struct ec_params_usb_pd_control *params;
210+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
211+
MAX(sizeof(struct ec_response_usb_pd_control_v1),
212+
sizeof(struct ec_params_usb_pd_control)));
213+
struct ec_response_usb_pd_control_v1 *resp =
214+
(struct ec_response_usb_pd_control_v1 *)msg->data;
215+
struct ec_params_usb_pd_control *params =
216+
(struct ec_params_usb_pd_control *)msg->data;
220217
int i;
221218

222-
msg = &ec_buf.msg;
223-
params = (struct ec_params_usb_pd_control *)msg->data;
224-
resp = (struct ec_response_usb_pd_control_v1 *)msg->data;
225-
226219
msg->command = EC_CMD_USB_PD_CONTROL;
227220
msg->version = 1;
228221
msg->insize = sizeof(*resp);
@@ -253,17 +246,15 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
253246

254247
static bool cros_ec_uptime_is_supported(struct cros_ec_device *ec_dev)
255248
{
256-
struct {
257-
struct cros_ec_command cmd;
258-
struct ec_response_uptime_info resp;
259-
} __packed msg = {};
249+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
250+
sizeof(struct ec_response_uptime_info));
260251
int ret;
261252

262-
msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
263-
msg.cmd.insize = sizeof(msg.resp);
253+
msg->command = EC_CMD_GET_UPTIME_INFO;
254+
msg->insize = sizeof(struct ec_response_uptime_info);
264255

265-
ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
266-
if (ret == -EPROTO && msg.cmd.result == EC_RES_INVALID_COMMAND)
256+
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
257+
if (ret == -EPROTO && msg->result == EC_RES_INVALID_COMMAND)
267258
return false;
268259

269260
/* Other errors maybe a transient error, do not rule about support. */
@@ -275,20 +266,17 @@ static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
275266
{
276267
struct cros_ec_debugfs *debug_info = file->private_data;
277268
struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
278-
struct {
279-
struct cros_ec_command cmd;
280-
struct ec_response_uptime_info resp;
281-
} __packed msg = {};
282-
struct ec_response_uptime_info *resp;
269+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
270+
sizeof(struct ec_response_uptime_info));
271+
struct ec_response_uptime_info *resp =
272+
(struct ec_response_uptime_info *)msg->data;
283273
char read_buf[32];
284274
int ret;
285275

286-
resp = (struct ec_response_uptime_info *)&msg.resp;
287-
288-
msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
289-
msg.cmd.insize = sizeof(*resp);
276+
msg->command = EC_CMD_GET_UPTIME_INFO;
277+
msg->insize = sizeof(*resp);
290278

291-
ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
279+
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
292280
if (ret < 0)
293281
return ret;
294282

0 commit comments

Comments
 (0)