Skip to content

Commit

Permalink
platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end …
Browse files Browse the repository at this point in the history
…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/platform/chrome/cros_ec_proto_test.c:1547: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_test.c:1607: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_test.c:1645: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_test.c:1668:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Link: KSPP#202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/ZgMaDl/of8YC445S@neat
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
  • Loading branch information
GustavoARSilva authored and Tzung-Bi Shih committed Mar 27, 2024
1 parent f749645 commit 6c85a13
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions drivers/platform/chrome/cros_ec_proto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1543,21 +1543,18 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
struct cros_ec_device *ec_dev = &priv->ec_dev;
struct ec_xfer_mock *mock;
int ret;
struct {
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);

ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd;

buf.msg.version = 0;
buf.msg.command = EC_CMD_HELLO;
buf.msg.insize = 4;
buf.msg.outsize = 2;
buf.data[0] = 0x55;
buf.data[1] = 0xaa;
buf->version = 0;
buf->command = EC_CMD_HELLO;
buf->insize = 4;
buf->outsize = 2;
buf->data[0] = 0x55;
buf->data[1] = 0xaa;

{
u8 *data;
Expand All @@ -1572,7 +1569,7 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
data[3] = 0x33;
}

ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
ret = cros_ec_cmd_xfer(ec_dev, buf);
KUNIT_EXPECT_EQ(test, ret, 4);

{
Expand All @@ -1590,10 +1587,10 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
KUNIT_EXPECT_EQ(test, data[0], 0x55);
KUNIT_EXPECT_EQ(test, data[1], 0xaa);

KUNIT_EXPECT_EQ(test, buf.data[0], 0xaa);
KUNIT_EXPECT_EQ(test, buf.data[1], 0x55);
KUNIT_EXPECT_EQ(test, buf.data[2], 0xcc);
KUNIT_EXPECT_EQ(test, buf.data[3], 0x33);
KUNIT_EXPECT_EQ(test, buf->data[0], 0xaa);
KUNIT_EXPECT_EQ(test, buf->data[1], 0x55);
KUNIT_EXPECT_EQ(test, buf->data[2], 0xcc);
KUNIT_EXPECT_EQ(test, buf->data[3], 0x33);
}
}

Expand All @@ -1603,26 +1600,23 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_insize(struct kunit *test)
struct cros_ec_device *ec_dev = &priv->ec_dev;
struct ec_xfer_mock *mock;
int ret;
struct {
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);

ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd;

buf.msg.version = 0;
buf.msg.command = EC_CMD_HELLO;
buf.msg.insize = 0xee + 1;
buf.msg.outsize = 2;
buf->version = 0;
buf->command = EC_CMD_HELLO;
buf->insize = 0xee + 1;
buf->outsize = 2;

{
mock = cros_kunit_ec_xfer_mock_add(test, 0xcc);
KUNIT_ASSERT_PTR_NE(test, mock, NULL);
}

ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
ret = cros_ec_cmd_xfer(ec_dev, buf);
KUNIT_EXPECT_EQ(test, ret, 0xcc);

{
Expand All @@ -1641,21 +1635,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru(stru
struct cros_ec_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev;
int ret;
struct {
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);

ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd;

buf.msg.version = 0;
buf.msg.command = EC_CMD_HELLO;
buf.msg.insize = 4;
buf.msg.outsize = 0xff + 1;
buf->version = 0;
buf->command = EC_CMD_HELLO;
buf->insize = 4;
buf->outsize = 0xff + 1;

ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
ret = cros_ec_cmd_xfer(ec_dev, buf);
KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
}

Expand All @@ -1664,21 +1655,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru(struct
struct cros_ec_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev;
int ret;
struct {
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);

ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd;

buf.msg.version = 0;
buf.msg.command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO;
buf.msg.insize = 4;
buf.msg.outsize = 0xdd + 1;
buf->version = 0;
buf->command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO;
buf->insize = 4;
buf->outsize = 0xdd + 1;

ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
ret = cros_ec_cmd_xfer(ec_dev, buf);
KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
}

Expand Down

0 comments on commit 6c85a13

Please sign in to comment.