ASoC: soc-topology: Avoid -Wflex-array-member-not-at-end warning
PATCH 1/1 ASoC: soc-topology: Avoid -Wflex-array-member-not-at-end warning
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the __TRAILING_OVERLAP() helper to fix the following warning:
sound/soc/soc-topology-test.c:136:38: 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.
Lastly, the static_assert() ensures the alignment between the FAM and struct snd_soc_tplg_hdr pcm_header; is not inadvertently changed, and it's intentionally placed immediately after the related structure (that is, no blank line in between).
--- sound/soc/soc-topology-test.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
sound/soc/soc-topology-test.c +8 -3
@@ -133,10 +133,15 @@ static struct tplg_tmpl_001 tplg_tmpl_empty = {struct tplg_tmpl_002 {struct snd_soc_tplg_hdr header; -struct snd_soc_tplg_manifest manifest; -struct snd_soc_tplg_hdr pcm_header; -struct snd_soc_tplg_pcm pcm; + +/* Must be last as it ends in a flexible-array member. */ + __TRAILING_OVERLAP(struct snd_soc_tplg_manifest, manifest, priv.data, __packed, + struct snd_soc_tplg_hdr pcm_header; +struct snd_soc_tplg_pcm pcm; + ); } __packed; +static_assert(offsetof(struct tplg_tmpl_002, manifest.priv.data) == + offsetof(struct tplg_tmpl_002, pcm_header));static struct tplg_tmpl_002 tplg_tmpl_with_pcm = { .header = {
Signature · 1 line
2.51.0
Mark Brown
maintainerQuoted 6 lines · Gustavo A. R. Silva
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the
__TRAILING_OVERLAP()helper to fix the following warning:
sound/soc/soc-topology-test.c:136:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Sashiko is complaining about this breaking some of the users:
https://sashiko.dev/#/patchset/afKSFY3qrlSOJ0EJ%40kspp
I don't know enough to tell if that's actually a sensible report or not.
Quoted 6 lines · Mark Brown
Quoted 5 lines · Gustavo A. R. Silva
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.
Use the
__TRAILING_OVERLAP()helper to fix the following warning:
Quoted 7 lines
Quoted 1 line
sound/soc/soc-topology-test.c:136:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]Sashiko is complaining about this breaking some of the users:
https://sashiko.dev/#/patchset/afKSFY3qrlSOJ0EJ%40kspp
I don't know enough to tell if that's actually a sensible report or not.
It seems Sashiko is correct here.
I'll rework this patch.
Thanks!
-Gustavo