All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
@ 2025-03-27 17:12 Gustavo A. R. Silva
  2025-03-28  4:41 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2025-03-27 17:12 UTC (permalink / raw)
  To: Lukasz Majczak, Wim Van Sebroeck, Guenter Roeck, Benson Leung,
	Tzung-Bi Shih
  Cc: chrome-platform, linux-watchdog, 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 on-stack definitions 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/watchdog/cros_ec_wdt.c:29:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes v2:
 - Fix truncated line in changelog text. (Tzung-Bi)
 - Update variable name: s/buf/msg (Tzung-Bi)
 - Cast to structs instead of union. (Tzung-Bi)
 - Add RB tag.

v1:
 - Link: https://lore.kernel.org/linux-hardening/Z-SBITmMfwjocYwL@kspp/

 drivers/watchdog/cros_ec_wdt.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
index 716c23f4388c..9ffe7f505645 100644
--- a/drivers/watchdog/cros_ec_wdt.c
+++ b/drivers/watchdog/cros_ec_wdt.c
@@ -25,26 +25,22 @@ static int cros_ec_wdt_send_cmd(struct cros_ec_device *cros_ec,
 				union cros_ec_wdt_data *arg)
 {
 	int ret;
-	struct {
-		struct cros_ec_command msg;
-		union cros_ec_wdt_data data;
-	} __packed buf = {
-		.msg = {
-			.version = 0,
-			.command = EC_CMD_HANG_DETECT,
-			.insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
-				   sizeof(struct ec_response_hang_detect) :
-				   0,
-			.outsize = sizeof(struct ec_params_hang_detect),
-		},
-		.data.req = arg->req
-	};
-
-	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
+	DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+			sizeof(union cros_ec_wdt_data));
+
+	msg->version = 0;
+	msg->command = EC_CMD_HANG_DETECT;
+	msg->insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
+		   sizeof(struct ec_response_hang_detect) :
+		   0;
+	msg->outsize = sizeof(struct ec_params_hang_detect);
+	*(struct ec_params_hang_detect *)msg->data = arg->req;
+
+	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
 	if (ret < 0)
 		return ret;
 
-	arg->resp = buf.data.resp;
+	arg->resp = *(struct ec_response_hang_detect *)msg->data;
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
  2025-03-27 17:12 [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-03-28  4:41 ` Guenter Roeck
  2025-04-07 19:13 ` Kees Cook
  2025-04-16  0:24 ` Gustavo A. R. Silva
  2 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2025-03-28  4:41 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Lukasz Majczak, Wim Van Sebroeck,
	Benson Leung, Tzung-Bi Shih
  Cc: chrome-platform, linux-watchdog, linux-kernel, linux-hardening

On 3/27/25 10:12, 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 on-stack definitions 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/watchdog/cros_ec_wdt.c:29:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
  2025-03-27 17:12 [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
  2025-03-28  4:41 ` Guenter Roeck
@ 2025-04-07 19:13 ` Kees Cook
  2025-04-07 19:42   ` Gustavo A. R. Silva
  2025-04-16  0:24 ` Gustavo A. R. Silva
  2 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2025-04-07 19:13 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Lukasz Majczak, Wim Van Sebroeck, Guenter Roeck, Benson Leung,
	Tzung-Bi Shih, chrome-platform, linux-watchdog, linux-kernel,
	linux-hardening

On Thu, Mar 27, 2025 at 11:12:11AM -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 on-stack definitions 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/watchdog/cros_ec_wdt.c:29:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes v2:
>  - Fix truncated line in changelog text. (Tzung-Bi)
>  - Update variable name: s/buf/msg (Tzung-Bi)
>  - Cast to structs instead of union. (Tzung-Bi)
>  - Add RB tag.
> 
> v1:
>  - Link: https://lore.kernel.org/linux-hardening/Z-SBITmMfwjocYwL@kspp/
> 
>  drivers/watchdog/cros_ec_wdt.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
> index 716c23f4388c..9ffe7f505645 100644
> --- a/drivers/watchdog/cros_ec_wdt.c
> +++ b/drivers/watchdog/cros_ec_wdt.c
> @@ -25,26 +25,22 @@ static int cros_ec_wdt_send_cmd(struct cros_ec_device *cros_ec,
>  				union cros_ec_wdt_data *arg)
>  {
>  	int ret;
> -	struct {
> -		struct cros_ec_command msg;
> -		union cros_ec_wdt_data data;
> -	} __packed buf = {
> -		.msg = {
> -			.version = 0,
> -			.command = EC_CMD_HANG_DETECT,
> -			.insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
> -				   sizeof(struct ec_response_hang_detect) :
> -				   0,
> -			.outsize = sizeof(struct ec_params_hang_detect),
> -		},
> -		.data.req = arg->req
> -	};
> -
> -	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
> +	DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> +			sizeof(union cros_ec_wdt_data));
> +
> +	msg->version = 0;

Technically redundant, but it was redundant before, so keeping style is
okay.

> +	msg->command = EC_CMD_HANG_DETECT;
> +	msg->insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
> +		   sizeof(struct ec_response_hang_detect) :
> +		   0;
> +	msg->outsize = sizeof(struct ec_params_hang_detect);
> +	*(struct ec_params_hang_detect *)msg->data = arg->req;
> +
> +	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
>  	if (ret < 0)
>  		return ret;
>  
> -	arg->resp = buf.data.resp;
> +	arg->resp = *(struct ec_response_hang_detect *)msg->data;

msg->data used twice and a "sizeof()" earlier... might be nicer to have
an explicit pointer?

-Kees

>  
>  	return 0;
>  }
> -- 
> 2.43.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
  2025-04-07 19:13 ` Kees Cook
@ 2025-04-07 19:42   ` Gustavo A. R. Silva
  2025-04-07 20:36     ` Kees Cook
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-07 19:42 UTC (permalink / raw)
  To: Kees Cook, Gustavo A. R. Silva
  Cc: Lukasz Majczak, Wim Van Sebroeck, Guenter Roeck, Benson Leung,
	Tzung-Bi Shih, chrome-platform, linux-watchdog, linux-kernel,
	linux-hardening


> 
>> +	msg->command = EC_CMD_HANG_DETECT;
>> +	msg->insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
>> +		   sizeof(struct ec_response_hang_detect) :
>> +		   0;
>> +	msg->outsize = sizeof(struct ec_params_hang_detect);
>> +	*(struct ec_params_hang_detect *)msg->data = arg->req;
>> +
>> +	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
>>   	if (ret < 0)
>>   		return ret;
>>   
>> -	arg->resp = buf.data.resp;
>> +	arg->resp = *(struct ec_response_hang_detect *)msg->data;
> 
> msg->data used twice and a "sizeof()" earlier... might be nicer to have
> an explicit pointer?

Those are two different pointers:

*(struct ec_params_hang_detect *)msg->data = arg->req;
arg->resp = *(struct ec_response_hang_detect *)msg->data;

--
Gustavo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
  2025-04-07 19:42   ` Gustavo A. R. Silva
@ 2025-04-07 20:36     ` Kees Cook
  0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2025-04-07 20:36 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Gustavo A. R. Silva, Lukasz Majczak, Wim Van Sebroeck,
	Guenter Roeck, Benson Leung, Tzung-Bi Shih, chrome-platform,
	linux-watchdog, linux-kernel, linux-hardening

On Mon, Apr 07, 2025 at 01:42:07PM -0600, Gustavo A. R. Silva wrote:
> 
> > 
> > > +	msg->command = EC_CMD_HANG_DETECT;
> > > +	msg->insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
> > > +		   sizeof(struct ec_response_hang_detect) :
> > > +		   0;
> > > +	msg->outsize = sizeof(struct ec_params_hang_detect);
> > > +	*(struct ec_params_hang_detect *)msg->data = arg->req;
> > > +
> > > +	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
> > >   	if (ret < 0)
> > >   		return ret;
> > > -	arg->resp = buf.data.resp;
> > > +	arg->resp = *(struct ec_response_hang_detect *)msg->data;
> > 
> > msg->data used twice and a "sizeof()" earlier... might be nicer to have
> > an explicit pointer?
> 
> Those are two different pointers:
> 
> *(struct ec_params_hang_detect *)msg->data = arg->req;
> arg->resp = *(struct ec_response_hang_detect *)msg->data;

Argh. I did it again. I can't see "params" vs "response". q_q

Sorry for the noise!

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning
  2025-03-27 17:12 [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
  2025-03-28  4:41 ` Guenter Roeck
  2025-04-07 19:13 ` Kees Cook
@ 2025-04-16  0:24 ` Gustavo A. R. Silva
  2 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-16  0:24 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Lukasz Majczak, Wim Van Sebroeck,
	Guenter Roeck, Benson Leung, Tzung-Bi Shih
  Cc: chrome-platform, linux-watchdog, linux-kernel, linux-hardening,
	Kees Cook

Hi all,

Friendly ping: who can take this patch, please? 🙂

Thanks!
-Gustavo

On 27/03/25 11:12, 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 on-stack definitions 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/watchdog/cros_ec_wdt.c:29:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes v2:
>   - Fix truncated line in changelog text. (Tzung-Bi)
>   - Update variable name: s/buf/msg (Tzung-Bi)
>   - Cast to structs instead of union. (Tzung-Bi)
>   - Add RB tag.
> 
> v1:
>   - Link: https://lore.kernel.org/linux-hardening/Z-SBITmMfwjocYwL@kspp/
> 
>   drivers/watchdog/cros_ec_wdt.c | 30 +++++++++++++-----------------
>   1 file changed, 13 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/watchdog/cros_ec_wdt.c b/drivers/watchdog/cros_ec_wdt.c
> index 716c23f4388c..9ffe7f505645 100644
> --- a/drivers/watchdog/cros_ec_wdt.c
> +++ b/drivers/watchdog/cros_ec_wdt.c
> @@ -25,26 +25,22 @@ static int cros_ec_wdt_send_cmd(struct cros_ec_device *cros_ec,
>   				union cros_ec_wdt_data *arg)
>   {
>   	int ret;
> -	struct {
> -		struct cros_ec_command msg;
> -		union cros_ec_wdt_data data;
> -	} __packed buf = {
> -		.msg = {
> -			.version = 0,
> -			.command = EC_CMD_HANG_DETECT,
> -			.insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
> -				   sizeof(struct ec_response_hang_detect) :
> -				   0,
> -			.outsize = sizeof(struct ec_params_hang_detect),
> -		},
> -		.data.req = arg->req
> -	};
> -
> -	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
> +	DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> +			sizeof(union cros_ec_wdt_data));
> +
> +	msg->version = 0;
> +	msg->command = EC_CMD_HANG_DETECT;
> +	msg->insize  = (arg->req.command == EC_HANG_DETECT_CMD_GET_STATUS) ?
> +		   sizeof(struct ec_response_hang_detect) :
> +		   0;
> +	msg->outsize = sizeof(struct ec_params_hang_detect);
> +	*(struct ec_params_hang_detect *)msg->data = arg->req;
> +
> +	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
>   	if (ret < 0)
>   		return ret;
>   
> -	arg->resp = buf.data.resp;
> +	arg->resp = *(struct ec_response_hang_detect *)msg->data;
>   
>   	return 0;
>   }


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-16  0:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-27 17:12 [PATCH v2][next] watchdog: cros-ec: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-03-28  4:41 ` Guenter Roeck
2025-04-07 19:13 ` Kees Cook
2025-04-07 19:42   ` Gustavo A. R. Silva
2025-04-07 20:36     ` Kees Cook
2025-04-16  0:24 ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.