[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z9EZByipsNmBoVea@google.com>
Date: Wed, 12 Mar 2025 05:17:59 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Alexandre Belloni <alexandre.belloni@...tlin.com>,
Benson Leung <bleung@...omium.org>,
Guenter Roeck <groeck@...omium.org>, linux-rtc@...r.kernel.org,
chrome-platform@...ts.linux.dev, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [RFC] rtc: Avoid a couple of -Wflex-array-member-not-at-end
warnings
On Mon, Mar 10, 2025 at 03:46:26PM +1030, Gustavo A. R. Silva wrote:
> Hi all,
>
> As part of the efforts to globally enable -Wflex-array-member-not-at-end,
> I'm currently trying to fix the following warnings:
>
> 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]
>
> The issue is that `struct cros_ec_command` is a flexible structure (which
> means that it contains a flexible-array member), and there is an object
> of this type (msg) declared within another structure but at the end.
^ not
> It seems that the following patch would suffice, as long as the flex-array
> member in `struct cros_ec_command` is not expected to be accessed and
> overlap with `struct ec_response_rtc data` in a "controlled manner":
>
> diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
> index 865c2e82c7a5..7e9bbab47e4c 100644
> --- a/drivers/rtc/rtc-cros-ec.c
> +++ b/drivers/rtc/rtc-cros-ec.c
> @@ -37,8 +37,8 @@ static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
> {
> int ret;
> struct {
> - struct cros_ec_command msg;
> struct ec_response_rtc data;
> + struct cros_ec_command msg;
> } __packed msg;
>
> memset(&msg, 0, sizeof(msg));
> @@ -59,8 +59,8 @@ static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
> {
> int ret;
> struct {
> - struct cros_ec_command msg;
> struct ec_response_rtc data;
> + struct cros_ec_command msg;
> } __packed msg;
>
> memset(&msg, 0, sizeof(msg));
This doesn't work. The header (i.e. struct cros_ec_command) is expected to
allocate right before the payload (e.g. struct ec_response_rtc)[1][2].
[1]: https://elixir.bootlin.com/linux/v6.14-rc1/source/drivers/platform/chrome/cros_ec_proto.c#L82
[2]: https://elixir.bootlin.com/linux/v6.14-rc1/source/drivers/platform/chrome/cros_ec_i2c.c#L166
> Otherwise, we probably need to use struct_group_tagged() as follows:
I'm not a big fan of the solution. How about using something similar to:
struct cros_ec_command *msg = kzalloc(sizeof(*msg) +
sizeof(struct ec_response_rtc), ...);
Powered by blists - more mailing lists