public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning
@ 2025-03-31 17:01 Gustavo A. R. Silva
  2025-03-31 18:01 ` Thomas Weißschuh
  2025-04-04 14:45 ` (subset) " Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-03-31 17:01 UTC (permalink / raw)
  To: Thomas Weißschuh, Lee Jones, Pavel Machek, Benson Leung,
	Guenter Roeck
  Cc: linux-leds, 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.

Replace an on-stack definition of a flexible structure with a call
to utility function cros_ec_cmd().

So, with these changes, fix the following warning:

drivers/leds/leds-cros_ec.c:70: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>
---
Changes in v2:
 - Use utility function cros_ec_cmd() instead of DEFINE_RAW_FLEX(). (Thomas Weißschuh)

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

 drivers/leds/leds-cros_ec.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c
index 275522b81ea5..377cf04e202a 100644
--- a/drivers/leds/leds-cros_ec.c
+++ b/drivers/leds/leds-cros_ec.c
@@ -60,31 +60,18 @@ static inline struct cros_ec_led_priv *cros_ec_led_cdev_to_priv(struct led_class
 union cros_ec_led_cmd_data {
 	struct ec_params_led_control req;
 	struct ec_response_led_control resp;
-} __packed;
+};
 
 static int cros_ec_led_send_cmd(struct cros_ec_device *cros_ec,
 				union cros_ec_led_cmd_data *arg)
 {
 	int ret;
-	struct {
-		struct cros_ec_command msg;
-		union cros_ec_led_cmd_data data;
-	} __packed buf = {
-		.msg = {
-			.version = 1,
-			.command = EC_CMD_LED_CONTROL,
-			.insize  = sizeof(arg->resp),
-			.outsize = sizeof(arg->req),
-		},
-		.data.req = arg->req
-	};
-
-	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
+
+	ret = cros_ec_cmd(cros_ec, 1, EC_CMD_LED_CONTROL, &arg->req,
+			  sizeof(arg->req), &arg->resp, sizeof(arg->resp));
 	if (ret < 0)
 		return ret;
 
-	arg->resp = buf.data.resp;
-
 	return 0;
 }
 
-- 
2.43.0


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

* Re: [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning
  2025-03-31 17:01 [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-03-31 18:01 ` Thomas Weißschuh
  2025-04-04 14:45 ` (subset) " Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2025-03-31 18:01 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Lee Jones, Pavel Machek, Benson Leung, Guenter Roeck, linux-leds,
	chrome-platform, linux-kernel, linux-hardening

On 2025-03-31 11:01:38-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.
> 
> Replace an on-stack definition of a flexible structure with a call
> to utility function cros_ec_cmd().
> 
> So, with these changes, fix the following warning:
> 
> drivers/leds/leds-cros_ec.c:70: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>

Thanks!

Acked-by: Thomas Weißschuh <linux@weissschuh.net>

> ---
> Changes in v2:
>  - Use utility function cros_ec_cmd() instead of DEFINE_RAW_FLEX(). (Thomas Weißschuh)
> 
> v1:
>  - Link: https://lore.kernel.org/linux-hardening/Z-azMlPnP7nPPJrY@kspp/
> 
>  drivers/leds/leds-cros_ec.c | 21 ++++-----------------
>  1 file changed, 4 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c
> index 275522b81ea5..377cf04e202a 100644
> --- a/drivers/leds/leds-cros_ec.c
> +++ b/drivers/leds/leds-cros_ec.c
> @@ -60,31 +60,18 @@ static inline struct cros_ec_led_priv *cros_ec_led_cdev_to_priv(struct led_class
>  union cros_ec_led_cmd_data {
>  	struct ec_params_led_control req;
>  	struct ec_response_led_control resp;
> -} __packed;
> +};
>  
>  static int cros_ec_led_send_cmd(struct cros_ec_device *cros_ec,
>  				union cros_ec_led_cmd_data *arg)
>  {
>  	int ret;
> -	struct {
> -		struct cros_ec_command msg;
> -		union cros_ec_led_cmd_data data;
> -	} __packed buf = {
> -		.msg = {
> -			.version = 1,
> -			.command = EC_CMD_LED_CONTROL,
> -			.insize  = sizeof(arg->resp),
> -			.outsize = sizeof(arg->req),
> -		},
> -		.data.req = arg->req
> -	};
> -
> -	ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg);
> +
> +	ret = cros_ec_cmd(cros_ec, 1, EC_CMD_LED_CONTROL, &arg->req,
> +			  sizeof(arg->req), &arg->resp, sizeof(arg->resp));
>  	if (ret < 0)
>  		return ret;
>  
> -	arg->resp = buf.data.resp;
> -
>  	return 0;
>  }
>  
> -- 
> 2.43.0
> 

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

* Re: (subset) [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning
  2025-03-31 17:01 [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
  2025-03-31 18:01 ` Thomas Weißschuh
@ 2025-04-04 14:45 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2025-04-04 14:45 UTC (permalink / raw)
  To: Thomas Weißschuh, Lee Jones, Pavel Machek, Benson Leung,
	Guenter Roeck, Gustavo A. R. Silva
  Cc: linux-leds, chrome-platform, linux-kernel, linux-hardening

On Mon, 31 Mar 2025 11:01:38 -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.
> 
> Replace an on-stack definition of a flexible structure with a call
> to utility function cros_ec_cmd().
> 
> So, with these changes, fix the following warning:
> 
> [...]

Applied, thanks!

[1/1] leds: Avoid -Wflex-array-member-not-at-end warning
      commit: c0adca7285b2bdf2ef7a67bb02e282d861e7b6a8

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2025-04-04 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 17:01 [PATCH v2][next] leds: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-03-31 18:01 ` Thomas Weißschuh
2025-04-04 14:45 ` (subset) " Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox