Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/Z-afGnRbyGs4dHb1@kspp
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Gustavo A. R. Silva and committed by
Tzung-Bi Shih
04251bc8 db4ea66a

+8 -16
+8 -16
drivers/platform/chrome/cros_kbd_led_backlight.c
··· 137 137 keyboard_led_set_brightness_ec_pwm(struct led_classdev *cdev, 138 138 enum led_brightness brightness) 139 139 { 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; 146 144 struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev); 147 - 148 - memset(&buf, 0, sizeof(buf)); 149 145 150 146 msg->command = EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT; 151 147 msg->outsize = sizeof(*params); ··· 154 158 static enum led_brightness 155 159 keyboard_led_get_brightness_ec_pwm(struct led_classdev *cdev) 156 160 { 157 - struct { 158 - struct cros_ec_command msg; 159 - struct ec_response_pwm_get_keyboard_backlight resp; 160 - } __packed buf; 161 - struct ec_response_pwm_get_keyboard_backlight *resp = &buf.resp; 162 - struct cros_ec_command *msg = &buf.msg; 161 + DEFINE_RAW_FLEX(struct cros_ec_command, msg, data, 162 + sizeof(struct ec_response_pwm_get_keyboard_backlight)); 163 + struct ec_response_pwm_get_keyboard_backlight *resp = 164 + (struct ec_response_pwm_get_keyboard_backlight *)msg->data; 163 165 struct keyboard_led *keyboard_led = container_of(cdev, struct keyboard_led, cdev); 164 166 int ret; 165 - 166 - memset(&buf, 0, sizeof(buf)); 167 167 168 168 msg->command = EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT; 169 169 msg->insize = sizeof(*resp);