Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/chrome: cros_ec_proto: 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_proto.c:143: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_proto.c:761: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-adX1BB30dcSJ7x@kspp
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Gustavo A. R. Silva and committed by
Tzung-Bi Shih
db4ea66a 8dc528be

+8 -13
+8 -13
drivers/platform/chrome/cros_ec_proto.c
··· 139 139 140 140 static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result) 141 141 { 142 - struct { 143 - struct cros_ec_command msg; 144 - struct ec_response_get_comms_status status; 145 - } __packed buf; 146 - struct cros_ec_command *msg = &buf.msg; 147 - struct ec_response_get_comms_status *status = &buf.status; 142 + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, 143 + sizeof(struct ec_response_get_comms_status)); 144 + struct ec_response_get_comms_status *status = 145 + (struct ec_response_get_comms_status *)msg->data; 148 146 int ret = 0, i; 149 147 150 148 msg->version = 0; ··· 755 757 756 758 static int get_next_event(struct cros_ec_device *ec_dev) 757 759 { 758 - struct { 759 - struct cros_ec_command msg; 760 - struct ec_response_get_next_event_v3 event; 761 - } __packed buf; 762 - struct cros_ec_command *msg = &buf.msg; 763 - struct ec_response_get_next_event_v3 *event = &buf.event; 760 + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, 761 + sizeof(struct ec_response_get_next_event_v3)); 762 + struct ec_response_get_next_event_v3 *event = 763 + (struct ec_response_get_next_event_v3 *)msg->data; 764 764 int cmd_version = ec_dev->mkbp_event_supported - 1; 765 765 u32 size; 766 766 767 - memset(msg, 0, sizeof(*msg)); 768 767 if (ec_dev->suspended) { 769 768 dev_dbg(ec_dev->dev, "Device suspended.\n"); 770 769 return -EHOSTDOWN;