Commit 41f4bc61 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Tzung-Bi Shih

platform/chrome: cros_ec_proto: avoid -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/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: https://github.com/KSPP/linux/issues/202Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/ZgMaDl/of8YC445S@neatSigned-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
parent 48e49af7
...@@ -1543,21 +1543,18 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test) ...@@ -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 cros_ec_device *ec_dev = &priv->ec_dev;
struct ec_xfer_mock *mock; struct ec_xfer_mock *mock;
int ret; int ret;
struct { DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
ec_dev->max_request = 0xff; ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee; ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd; ec_dev->max_passthru = 0xdd;
buf.msg.version = 0; buf->version = 0;
buf.msg.command = EC_CMD_HELLO; buf->command = EC_CMD_HELLO;
buf.msg.insize = 4; buf->insize = 4;
buf.msg.outsize = 2; buf->outsize = 2;
buf.data[0] = 0x55; buf->data[0] = 0x55;
buf.data[1] = 0xaa; buf->data[1] = 0xaa;
{ {
u8 *data; u8 *data;
...@@ -1572,7 +1569,7 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test) ...@@ -1572,7 +1569,7 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
data[3] = 0x33; 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); KUNIT_EXPECT_EQ(test, ret, 4);
{ {
...@@ -1590,10 +1587,10 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test) ...@@ -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[0], 0x55);
KUNIT_EXPECT_EQ(test, data[1], 0xaa); KUNIT_EXPECT_EQ(test, data[1], 0xaa);
KUNIT_EXPECT_EQ(test, buf.data[0], 0xaa); KUNIT_EXPECT_EQ(test, buf->data[0], 0xaa);
KUNIT_EXPECT_EQ(test, buf.data[1], 0x55); KUNIT_EXPECT_EQ(test, buf->data[1], 0x55);
KUNIT_EXPECT_EQ(test, buf.data[2], 0xcc); KUNIT_EXPECT_EQ(test, buf->data[2], 0xcc);
KUNIT_EXPECT_EQ(test, buf.data[3], 0x33); KUNIT_EXPECT_EQ(test, buf->data[3], 0x33);
} }
} }
...@@ -1603,26 +1600,23 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_insize(struct kunit *test) ...@@ -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 cros_ec_device *ec_dev = &priv->ec_dev;
struct ec_xfer_mock *mock; struct ec_xfer_mock *mock;
int ret; int ret;
struct { DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
ec_dev->max_request = 0xff; ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee; ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd; ec_dev->max_passthru = 0xdd;
buf.msg.version = 0; buf->version = 0;
buf.msg.command = EC_CMD_HELLO; buf->command = EC_CMD_HELLO;
buf.msg.insize = 0xee + 1; buf->insize = 0xee + 1;
buf.msg.outsize = 2; buf->outsize = 2;
{ {
mock = cros_kunit_ec_xfer_mock_add(test, 0xcc); mock = cros_kunit_ec_xfer_mock_add(test, 0xcc);
KUNIT_ASSERT_PTR_NE(test, mock, NULL); 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); KUNIT_EXPECT_EQ(test, ret, 0xcc);
{ {
...@@ -1641,21 +1635,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru(stru ...@@ -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_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev; struct cros_ec_device *ec_dev = &priv->ec_dev;
int ret; int ret;
struct { DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
ec_dev->max_request = 0xff; ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee; ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd; ec_dev->max_passthru = 0xdd;
buf.msg.version = 0; buf->version = 0;
buf.msg.command = EC_CMD_HELLO; buf->command = EC_CMD_HELLO;
buf.msg.insize = 4; buf->insize = 4;
buf.msg.outsize = 0xff + 1; 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); KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
} }
...@@ -1664,21 +1655,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru(struct ...@@ -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_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev; struct cros_ec_device *ec_dev = &priv->ec_dev;
int ret; int ret;
struct { DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
struct cros_ec_command msg;
u8 data[0x100];
} __packed buf;
ec_dev->max_request = 0xff; ec_dev->max_request = 0xff;
ec_dev->max_response = 0xee; ec_dev->max_response = 0xee;
ec_dev->max_passthru = 0xdd; ec_dev->max_passthru = 0xdd;
buf.msg.version = 0; buf->version = 0;
buf.msg.command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO; buf->command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO;
buf.msg.insize = 4; buf->insize = 4;
buf.msg.outsize = 0xdd + 1; 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); KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment