Skip to content

Commit 41f4bc6

Browse files
GustavoARSilvaTzung-Bi Shih
authored andcommitted
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: KSPP/linux#202 Signed-off-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/ZgMaDl/of8YC445S@neat Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 48e49af commit 41f4bc6

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

drivers/platform/chrome/cros_ec_proto_test.c

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,21 +1543,18 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
15431543
struct cros_ec_device *ec_dev = &priv->ec_dev;
15441544
struct ec_xfer_mock *mock;
15451545
int ret;
1546-
struct {
1547-
struct cros_ec_command msg;
1548-
u8 data[0x100];
1549-
} __packed buf;
1546+
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
15501547

15511548
ec_dev->max_request = 0xff;
15521549
ec_dev->max_response = 0xee;
15531550
ec_dev->max_passthru = 0xdd;
15541551

1555-
buf.msg.version = 0;
1556-
buf.msg.command = EC_CMD_HELLO;
1557-
buf.msg.insize = 4;
1558-
buf.msg.outsize = 2;
1559-
buf.data[0] = 0x55;
1560-
buf.data[1] = 0xaa;
1552+
buf->version = 0;
1553+
buf->command = EC_CMD_HELLO;
1554+
buf->insize = 4;
1555+
buf->outsize = 2;
1556+
buf->data[0] = 0x55;
1557+
buf->data[1] = 0xaa;
15611558

15621559
{
15631560
u8 *data;
@@ -1572,7 +1569,7 @@ static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test)
15721569
data[3] = 0x33;
15731570
}
15741571

1575-
ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
1572+
ret = cros_ec_cmd_xfer(ec_dev, buf);
15761573
KUNIT_EXPECT_EQ(test, ret, 4);
15771574

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

1593-
KUNIT_EXPECT_EQ(test, buf.data[0], 0xaa);
1594-
KUNIT_EXPECT_EQ(test, buf.data[1], 0x55);
1595-
KUNIT_EXPECT_EQ(test, buf.data[2], 0xcc);
1596-
KUNIT_EXPECT_EQ(test, buf.data[3], 0x33);
1590+
KUNIT_EXPECT_EQ(test, buf->data[0], 0xaa);
1591+
KUNIT_EXPECT_EQ(test, buf->data[1], 0x55);
1592+
KUNIT_EXPECT_EQ(test, buf->data[2], 0xcc);
1593+
KUNIT_EXPECT_EQ(test, buf->data[3], 0x33);
15971594
}
15981595
}
15991596

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

16111605
ec_dev->max_request = 0xff;
16121606
ec_dev->max_response = 0xee;
16131607
ec_dev->max_passthru = 0xdd;
16141608

1615-
buf.msg.version = 0;
1616-
buf.msg.command = EC_CMD_HELLO;
1617-
buf.msg.insize = 0xee + 1;
1618-
buf.msg.outsize = 2;
1609+
buf->version = 0;
1610+
buf->command = EC_CMD_HELLO;
1611+
buf->insize = 0xee + 1;
1612+
buf->outsize = 2;
16191613

16201614
{
16211615
mock = cros_kunit_ec_xfer_mock_add(test, 0xcc);
16221616
KUNIT_ASSERT_PTR_NE(test, mock, NULL);
16231617
}
16241618

1625-
ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
1619+
ret = cros_ec_cmd_xfer(ec_dev, buf);
16261620
KUNIT_EXPECT_EQ(test, ret, 0xcc);
16271621

16281622
{
@@ -1641,21 +1635,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru(stru
16411635
struct cros_ec_proto_test_priv *priv = test->priv;
16421636
struct cros_ec_device *ec_dev = &priv->ec_dev;
16431637
int ret;
1644-
struct {
1645-
struct cros_ec_command msg;
1646-
u8 data[0x100];
1647-
} __packed buf;
1638+
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
16481639

16491640
ec_dev->max_request = 0xff;
16501641
ec_dev->max_response = 0xee;
16511642
ec_dev->max_passthru = 0xdd;
16521643

1653-
buf.msg.version = 0;
1654-
buf.msg.command = EC_CMD_HELLO;
1655-
buf.msg.insize = 4;
1656-
buf.msg.outsize = 0xff + 1;
1644+
buf->version = 0;
1645+
buf->command = EC_CMD_HELLO;
1646+
buf->insize = 4;
1647+
buf->outsize = 0xff + 1;
16571648

1658-
ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
1649+
ret = cros_ec_cmd_xfer(ec_dev, buf);
16591650
KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
16601651
}
16611652

@@ -1664,21 +1655,18 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru(struct
16641655
struct cros_ec_proto_test_priv *priv = test->priv;
16651656
struct cros_ec_device *ec_dev = &priv->ec_dev;
16661657
int ret;
1667-
struct {
1668-
struct cros_ec_command msg;
1669-
u8 data[0x100];
1670-
} __packed buf;
1658+
DEFINE_RAW_FLEX(struct cros_ec_command, buf, data, 0x100);
16711659

16721660
ec_dev->max_request = 0xff;
16731661
ec_dev->max_response = 0xee;
16741662
ec_dev->max_passthru = 0xdd;
16751663

1676-
buf.msg.version = 0;
1677-
buf.msg.command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO;
1678-
buf.msg.insize = 4;
1679-
buf.msg.outsize = 0xdd + 1;
1664+
buf->version = 0;
1665+
buf->command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO;
1666+
buf->insize = 4;
1667+
buf->outsize = 0xdd + 1;
16801668

1681-
ret = cros_ec_cmd_xfer(ec_dev, &buf.msg);
1669+
ret = cros_ec_cmd_xfer(ec_dev, buf);
16821670
KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE);
16831671
}
16841672

0 commit comments

Comments
 (0)