* [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
@ 2025-03-28 13:07 Gustavo A. R. Silva
2025-04-01 9:56 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-03-28 13:07 UTC (permalink / raw)
To: Benson Leung, Tzung-Bi Shih
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_kbd_led_backlight.c:141: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_kbd_led_backlight.c:162: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>
---
.../platform/chrome/cros_kbd_led_backlight.c | 24 +++++++------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index fc27bd7fc4b9..f4c2282129f5 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -137,16 +137,12 @@ static int
keyboard_led_set_brightness_ec_pwm(struct led_classdev *cdev,
enum led_brightness brightness)
{
- struct {
- struct cros_ec_command msg;
- struct ec_params_pwm_set_keyboard_backlight params;
- } __packed buf;
- struct ec_params_pwm_set_keyboard_backlight *params = &buf.params;
- struct cros_ec_command *msg = &buf.msg;
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ sizeof(struct ec_params_pwm_set_keyboard_backlight));
+ struct ec_params_pwm_set_keyboard_backlight *params =
+ (struct ec_params_pwm_set_keyboard_backlight *)msg->data;
struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev);
- memset(&buf, 0, sizeof(buf));
-
msg->command = EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT;
msg->outsize = sizeof(*params);
@@ -158,17 +154,13 @@ keyboard_led_set_brightness_ec_pwm(struct led_classdev *cdev,
static enum led_brightness
keyboard_led_get_brightness_ec_pwm(struct led_classdev *cdev)
{
- struct {
- struct cros_ec_command msg;
- struct ec_response_pwm_get_keyboard_backlight resp;
- } __packed buf;
- struct ec_response_pwm_get_keyboard_backlight *resp = &buf.resp;
- struct cros_ec_command *msg = &buf.msg;
+ DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
+ sizeof(struct ec_response_pwm_get_keyboard_backlight));
+ struct ec_response_pwm_get_keyboard_backlight *resp =
+ (struct ec_response_pwm_get_keyboard_backlight *)msg->data;
struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev);
int ret;
- memset(&buf, 0, sizeof(buf));
-
msg->command = EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT;
msg->insize = sizeof(*resp);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
2025-03-28 13:07 [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
@ 2025-04-01 9:56 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2025-04-01 9:56 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Benson Leung, chrome-platform, linux-kernel, linux-hardening
On Fri, Mar 28, 2025 at 07:07:38AM -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_kbd_led_backlight.c:141: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_kbd_led_backlight.c:162: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] 3+ messages in thread
* Re: [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
2025-03-28 13:07 [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-04-01 9:56 ` Tzung-Bi Shih
@ 2025-04-07 2:16 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2025-04-07 2:16 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Benson Leung, chrome-platform, linux-kernel, linux-hardening
On Fri, Mar 28, 2025 at 07:07:38AM -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_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
commit: 04251bc86653a839ccb1f5ec248ad5e8afd9a627
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-07 2:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-28 13:07 [PATCH][next] platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-04-01 9:56 ` Tzung-Bi Shih
2025-04-07 2:16 ` Tzung-Bi Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox