platform/chrome: cros_ec_debugfs: Avoid -Wflex-array-member-not-at-end warnings
Subsystems (2)
PATCH 1/1 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]
--- drivers/platform/chrome/cros_ec_debugfs.c | 52 +++++++++-------------- 1 file changed, 20 insertions(+), 32 deletions(-)
drivers/platform/chrome/cros_ec_debugfs.c +20 -32
@@ -207,22 +207,15 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,char read_buf[EC_USB_PD_MAX_PORTS *40 ], *p = read_buf;struct cros_ec_debugfs *debug_info = file->private_data;struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; -struct { -struct cros_ec_command msg; -union { -struct ec_response_usb_pd_control_v1 resp; -struct ec_params_usb_pd_control params; - }; - } __packed ec_buf; -struct cros_ec_command *msg; -struct ec_response_usb_pd_control_v1 *resp; -struct ec_params_usb_pd_control *params; + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, + MAX(sizeof(struct ec_response_usb_pd_control_v1), + sizeof(struct ec_params_usb_pd_control))); +struct ec_response_usb_pd_control_v1 *resp = + (struct ec_response_usb_pd_control_v1 *)msg->data; +struct ec_params_usb_pd_control *params = + (struct ec_params_usb_pd_control *)msg->data;int i; - msg = &ec_buf.msg; - params = (struct ec_params_usb_pd_control *)msg->data; - resp = (struct ec_response_usb_pd_control_v1 *)msg->data; - msg->command =EC_CMD_USB_PD_CONTROL ; msg->version =1 ; msg->insize =sizeof (*resp);
@@ -253,17 +246,15 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,static bool cros_ec_uptime_is_supported (struct cros_ec_device *ec_dev) { -struct { -struct cros_ec_command cmd; -struct ec_response_uptime_info resp; - } __packed msg = {}; + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, + sizeof(struct ec_response_uptime_info));int ret; - msg.cmd.command =EC_CMD_GET_UPTIME_INFO ; - msg.cmd.insize =sizeof (msg.resp); + msg->command =EC_CMD_GET_UPTIME_INFO ; + msg->insize =sizeof (struct ec_response_uptime_info ); - ret =cros_ec_cmd_xfer_status (ec_dev, &msg.cmd); -if (ret == -EPROTO && msg.cmd.result ==EC_RES_INVALID_COMMAND ) + ret =cros_ec_cmd_xfer_status (ec_dev, msg); +if (ret == -EPROTO && msg->result ==EC_RES_INVALID_COMMAND )return false;/* 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, {struct cros_ec_debugfs *debug_info = file->private_data;struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; -struct { -struct cros_ec_command cmd; -struct ec_response_uptime_info resp; - } __packed msg = {}; -struct ec_response_uptime_info *resp; + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, + sizeof(struct ec_response_uptime_info)); +struct ec_response_uptime_info *resp = + (struct ec_response_uptime_info *)msg->data;char read_buf[32 ];int ret; - resp = (struct ec_response_uptime_info *)&msg.resp; - - msg.cmd.command =EC_CMD_GET_UPTIME_INFO ; - msg.cmd.insize =sizeof (*resp); + msg->command =EC_CMD_GET_UPTIME_INFO ; + msg->insize =sizeof (*resp); - ret =cros_ec_cmd_xfer_status (ec_dev, &msg.cmd); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret <0 )return ret;
Signature · 1 line
2.43.0
Quoted 8 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.
Quoted 7 lines
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]>
For my reference:
Tzung-Bi Shih
maintainerQuoted 9 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.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
[1/1] platform/chrome: cros_ec_debugfs: Avoid -Wflex-array-member-not-at-end warnings
commit: da90147bf52b7ab6d8f021418496a7b6f39b2249
Thanks!