Skip to content

Commit 0176188

Browse files
GustavoARSilvaalexandrebelloni
authored andcommitted
rtc: cros-ec: Avoid a couple of -Wflex-array-member-not-at-end warnings
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 warning: drivers/rtc/rtc-cros-ec.c:62:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/rtc/rtc-cros-ec.c:40: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> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/Z9PpPg06OK8ghNvm@kspp Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 6c2b833 commit 0176188

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

drivers/rtc/rtc-cros-ec.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,34 @@ struct cros_ec_rtc {
3535
static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
3636
u32 *response)
3737
{
38+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
39+
sizeof(struct ec_response_rtc));
3840
int ret;
39-
struct {
40-
struct cros_ec_command msg;
41-
struct ec_response_rtc data;
42-
} __packed msg;
4341

44-
memset(&msg, 0, sizeof(msg));
45-
msg.msg.command = command;
46-
msg.msg.insize = sizeof(msg.data);
42+
msg->command = command;
43+
msg->insize = sizeof(struct ec_response_rtc);
4744

48-
ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
45+
ret = cros_ec_cmd_xfer_status(cros_ec, msg);
4946
if (ret < 0)
5047
return ret;
5148

52-
*response = msg.data.time;
49+
*response = ((struct ec_response_rtc *)msg->data)->time;
5350

5451
return 0;
5552
}
5653

5754
static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
5855
u32 param)
5956
{
57+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
58+
sizeof(struct ec_response_rtc));
6059
int ret;
61-
struct {
62-
struct cros_ec_command msg;
63-
struct ec_response_rtc data;
64-
} __packed msg;
6560

66-
memset(&msg, 0, sizeof(msg));
67-
msg.msg.command = command;
68-
msg.msg.outsize = sizeof(msg.data);
69-
msg.data.time = param;
61+
msg->command = command;
62+
msg->outsize = sizeof(struct ec_response_rtc);
63+
((struct ec_response_rtc *)msg->data)->time = param;
7064

71-
ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
65+
ret = cros_ec_cmd_xfer_status(cros_ec, msg);
7266
if (ret < 0)
7367
return ret;
7468
return 0;

0 commit comments

Comments
 (0)