Re: [PATCH][next] rtc: Avoid a couple of -Wflex-array-member-not-at-end warnings

From: Tzung-Bi Shih
Date: Fri Mar 14 2025 - 04:17:26 EST


On Fri, Mar 14, 2025 at 11:14:54AM +1030, Gustavo A. R. Silva wrote:
> static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
> u32 *response)
> {
> + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> + sizeof(struct ec_response_rtc));
> int ret;
> - struct {
> - struct cros_ec_command msg;
> - struct ec_response_rtc data;
> - } __packed msg;
>
> - memset(&msg, 0, sizeof(msg));
> - msg.msg.command = command;
> - msg.msg.insize = sizeof(msg.data);
> + msg->command = command;
> + msg->insize = sizeof(struct ec_response_rtc);
>
> - ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
> + ret = cros_ec_cmd_xfer_status(cros_ec, msg);
> if (ret < 0)
> return ret;
>
> - *response = msg.data.time;
> + memcpy(response, msg->data, sizeof(*response));

Technically they are the same as `struct ec_response_rtc` only has an
u32 member. Any reason to not translate it something similar to:

*response = ((struct ec_response_rtc *)msg->data)->time;

>
> return 0;
> }
> @@ -57,18 +54,15 @@ static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
> static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
> u32 param)
> {
> + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> + sizeof(struct ec_response_rtc));
> int ret;
> - struct {
> - struct cros_ec_command msg;
> - struct ec_response_rtc data;
> - } __packed msg;
>
> - memset(&msg, 0, sizeof(msg));
> - msg.msg.command = command;
> - msg.msg.outsize = sizeof(msg.data);
> - msg.data.time = param;
> + msg->command = command;
> + msg->outsize = sizeof(struct ec_response_rtc);
> + memcpy(msg->data, &param, sizeof(param));

Same here, how about:

((struct ec_response_rtc *)msg->data)->time = param;