* [PATCH][next] platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end warnings
@ 2024-03-26 18:55 Gustavo A. R. Silva
2024-03-27 4:48 ` patchwork-bot+chrome-platform
2024-03-27 4:48 ` patchwork-bot+chrome-platform
0 siblings, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2024-03-26 18:55 UTC (permalink / raw)
To: Benson Leung, Tzung-Bi Shih, Guenter Roeck
Cc: chrome-platform, linux-kernel, Gustavo A. R. Silva,
linux-hardening
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/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 72 ++++++++------------
1 file changed, 30 insertions(+), 42 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index b6169d6f2467..41378c2ee6a0 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -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;
@@ -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);
{
@@ -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);
}
}
@@ -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);
{
@@ -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);
}
@@ -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);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end warnings
2024-03-26 18:55 [PATCH][next] platform/chrome: cros_ec_proto: avoid " Gustavo A. R. Silva
@ 2024-03-27 4:48 ` patchwork-bot+chrome-platform
2024-03-27 4:48 ` patchwork-bot+chrome-platform
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-27 4:48 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: bleung, tzungbi, groeck, chrome-platform, linux-kernel,
linux-hardening
Hello:
This patch was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:
On Tue, 26 Mar 2024 12:55:10 -0600 you wrote:
> 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]
>
> [...]
Here is the summary with links:
- [next] platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end warnings
https://git.kernel.org/chrome-platform/c/6c85a13b133f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end warnings
2024-03-26 18:55 [PATCH][next] platform/chrome: cros_ec_proto: avoid " Gustavo A. R. Silva
2024-03-27 4:48 ` patchwork-bot+chrome-platform
@ 2024-03-27 4:48 ` patchwork-bot+chrome-platform
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-27 4:48 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: bleung, tzungbi, groeck, chrome-platform, linux-kernel,
linux-hardening
Hello:
This patch was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:
On Tue, 26 Mar 2024 12:55:10 -0600 you wrote:
> 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]
>
> [...]
Here is the summary with links:
- [next] platform/chrome: cros_ec_proto: avoid -Wflex-array-member-not-at-end warnings
https://git.kernel.org/chrome-platform/c/6c85a13b133f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings
@ 2025-03-28 13:00 Gustavo A. R. Silva
2025-04-01 9:52 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
0 siblings, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2025-03-28 13:00 UTC (permalink / raw)
To: Benson Leung, Tzung-Bi Shih, Guenter Roeck
Cc: chrome-platform, linux-kernel, Gustavo A. R. Silva,
linux-hardening
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.
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 warnings:
drivers/platform/chrome/cros_ec_proto.c:143: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.c:761: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>
---
drivers/platform/chrome/cros_ec_proto.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 877b107fee4b..586358fbf981 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -139,12 +139,10 @@ static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_co
static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result)
{
- struct {
- struct cros_ec_command msg;
- struct ec_response_get_comms_status status;
- } __packed buf;
- struct cros_ec_command *msg = &buf.msg;
- struct ec_response_get_comms_status *status = &buf.status;
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ sizeof(struct ec_response_get_comms_status));
+ struct ec_response_get_comms_status *status =
+ (struct ec_response_get_comms_status *)msg->data;
int ret = 0, i;
msg->version = 0;
@@ -757,16 +755,13 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev,
static int get_next_event(struct cros_ec_device *ec_dev)
{
- struct {
- struct cros_ec_command msg;
- struct ec_response_get_next_event_v3 event;
- } __packed buf;
- struct cros_ec_command *msg = &buf.msg;
- struct ec_response_get_next_event_v3 *event = &buf.event;
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ sizeof(struct ec_response_get_next_event_v3));
+ struct ec_response_get_next_event_v3 *event =
+ (struct ec_response_get_next_event_v3 *)msg->data;
int cmd_version = ec_dev->mkbp_event_supported - 1;
u32 size;
- memset(msg, 0, sizeof(*msg));
if (ec_dev->suspended) {
dev_dbg(ec_dev->dev, "Device suspended.\n");
return -EHOSTDOWN;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings
2025-03-28 13:00 [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
@ 2025-04-01 9:52 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
1 sibling, 0 replies; 6+ messages in thread
From: Tzung-Bi Shih @ 2025-04-01 9:52 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
linux-hardening
On Fri, Mar 28, 2025 at 07:00:15AM -0600, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> 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 warnings:
>
> drivers/platform/chrome/cros_ec_proto.c:143: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.c:761: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>
For my reference:
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings
2025-03-28 13:00 [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-04-01 9:52 ` Tzung-Bi Shih
@ 2025-04-07 2:16 ` Tzung-Bi Shih
1 sibling, 0 replies; 6+ messages in thread
From: Tzung-Bi Shih @ 2025-04-07 2:16 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
linux-hardening
On Fri, Mar 28, 2025 at 07:00:15AM -0600, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> 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.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
[1/1] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings
commit: db4ea66acddf95b4bb13ef17537097820218fb7a
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-07 2:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-28 13:00 [PATCH][next] platform/chrome: cros_ec_proto: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-04-01 9:52 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
-- strict thread matches above, loose matches on Subject: below --
2024-03-26 18:55 [PATCH][next] platform/chrome: cros_ec_proto: avoid " Gustavo A. R. Silva
2024-03-27 4:48 ` patchwork-bot+chrome-platform
2024-03-27 4:48 ` patchwork-bot+chrome-platform
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox