]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/chrome: cros_ec_debugfs: Avoid -Wflex-array-member-not-at-end warnings
authorGustavo A. R. Silva <gustavoars@kernel.org>
Fri, 28 Mar 2025 13:20:00 +0000 (07:20 -0600)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 7 Apr 2025 02:06:55 +0000 (02:06 +0000)
-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 <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/Z-aiAAcIP7sBRtz0@kspp
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/cros_ec_debugfs.c

index 92ac9a2f9c88f61c094bd367966feda0db9b35a1..d10f9561990c8ef8ac84eb2ce54a8bc2ad822f5c 100644 (file)
@@ -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;