Hello,

On Tue, Aug 12, 2025 at 11:35:41PM +0900, 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 new TRAILING_OVERLAP() helper to fix the following warnings:
> 
> drivers/pwm/pwm-cros-ec.c:53:40: warning: structure containing a flexible 
> array member is not at the end of another structure 
> [-Wflex-array-member-not-at-end]
> drivers/pwm/pwm-cros-ec.c:87:40: warning: structure containing a flexible 
> array member is not at the end of another structure 
> [-Wflex-array-member-not-at-end]
> 
> This helper creates a union between a flexible-array member (FAM)
> and a set of members that would otherwise follow it. This overlays
> the trailing members onto the FAM while preserving the original
> memory layout.
> 
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
>  drivers/pwm/pwm-cros-ec.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
> index 189301dc395e..67cfa17f58e0 100644
> --- a/drivers/pwm/pwm-cros-ec.c
> +++ b/drivers/pwm/pwm-cros-ec.c
> @@ -49,10 +49,9 @@ static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device 
> *ec_pwm, u8 index,
>                               u16 duty)
>  {
>       struct cros_ec_device *ec = ec_pwm->ec;
> -     struct {
> -             struct cros_ec_command msg;
> +     TRAILING_OVERLAP(struct cros_ec_command, msg, data,

It's a bit ugly to have to pass the name of the flexible array member.

I think the following would work:

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index dab49e2ec8c0..8ca9df87a523 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -108,7 +108,7 @@ enum {
        union {                                                                 
\
                TYPE NAME;                                                      
\
                struct {                                                        
\
-                       unsigned char __offset_to_##FAM[offsetof(TYPE, FAM)];   
\
+                       unsigned char __offset_to_##FAM[sizeof(TYPE)];          
\
                        MEMBERS                                                 
\
                };                                                              
\
        }

which only leaves one usage of FAM in the name of the padding struct
member. I'm sure someone is able to come up with something nice here to
get rid of FAM completely or point out what I'm missing.

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature

Reply via email to