Re: [PATCH][next] pwm: cros-ec: Avoid -Wflex-array-member-not-at-end warnings

From: Gustavo A. R. Silva
Date: Thu Aug 14 2025 - 07:49:48 EST



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.

Flexible structures (structs that contain a FAM) may have trailing padding.
Under that scenario sizeof(TYPE) causes the overlay between FAM and MEMBERS
to be misaligned.

On the other hand, offsetof(TYPE, FAM) precisely positions the trailing
MEMBERS where the FAM begins, which is correct and safe.

Thanks
-Gustavo