]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
authorGustavo A. R. Silva <gustavoars@kernel.org>
Fri, 28 Mar 2025 13:07:38 +0000 (07:07 -0600)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 7 Apr 2025 02:04:55 +0000 (02:04 +0000)
-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>
Link: https://lore.kernel.org/r/Z-afGnRbyGs4dHb1@kspp
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/cros_kbd_led_backlight.c

index fc27bd7fc4b9945110cf819004b21a67f910b5d8..f4c2282129f50bdb8a25c427fd0cc8176748e51e 100644 (file)
@@ -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);