Skip to content

Commit 04251bc

Browse files
GustavoARSilvaTzung-Bi Shih
authored andcommitted
platform/chrome: cros_kbd_led_backlight: Avoid -Wflex-array-member-not-at-end warnings
-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 <[email protected]> Link: https://lore.kernel.org/r/Z-afGnRbyGs4dHb1@kspp Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent db4ea66 commit 04251bc

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

drivers/platform/chrome/cros_kbd_led_backlight.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,12 @@ static int
137137
keyboard_led_set_brightness_ec_pwm(struct led_classdev *cdev,
138138
enum led_brightness brightness)
139139
{
140-
struct {
141-
struct cros_ec_command msg;
142-
struct ec_params_pwm_set_keyboard_backlight params;
143-
} __packed buf;
144-
struct ec_params_pwm_set_keyboard_backlight *params = &buf.params;
145-
struct cros_ec_command *msg = &buf.msg;
140+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
141+
sizeof(struct ec_params_pwm_set_keyboard_backlight));
142+
struct ec_params_pwm_set_keyboard_backlight *params =
143+
(struct ec_params_pwm_set_keyboard_backlight *)msg->data;
146144
struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev);
147145

148-
memset(&buf, 0, sizeof(buf));
149-
150146
msg->command = EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT;
151147
msg->outsize = sizeof(*params);
152148

@@ -158,17 +154,13 @@ keyboard_led_set_brightness_ec_pwm(struct led_classdev *cdev,
158154
static enum led_brightness
159155
keyboard_led_get_brightness_ec_pwm(struct led_classdev *cdev)
160156
{
161-
struct {
162-
struct cros_ec_command msg;
163-
struct ec_response_pwm_get_keyboard_backlight resp;
164-
} __packed buf;
165-
struct ec_response_pwm_get_keyboard_backlight *resp = &buf.resp;
166-
struct cros_ec_command *msg = &buf.msg;
157+
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
158+
sizeof(struct ec_response_pwm_get_keyboard_backlight));
159+
struct ec_response_pwm_get_keyboard_backlight *resp =
160+
(struct ec_response_pwm_get_keyboard_backlight *)msg->data;
167161
struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev);
168162
int ret;
169163

170-
memset(&buf, 0, sizeof(buf));
171-
172164
msg->command = EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT;
173165
msg->insize = sizeof(*resp);
174166

0 commit comments

Comments
 (0)