[PATCH] ASoC: soc-core: reset rtd->num_components after allocation

From: Shawn Guo

Date: Sat Nov 14 2026 - 03:38:49 EST


Since commit 4dd10fbbeb9c ("treewide: Convert devm_kmalloc() family to
the devm_kmalloc_obj() family"), the rtd is allocated with
devm_kzalloc_flex(). On compilers supporting __builtin_counted_by_ref()
(GCC >= 15, Clang >= 19), __alloc_flex() initializes the __counted_by()
counter of the flexible array to the allocated count. As components[]
is annotated with __counted_by(num_components), rtd->num_components now
starts at num_cpus + num_codecs + num_platforms instead of 0.

snd_soc_rtd_add_component() however fills components[] incrementally,
assuming num_components starts from 0. With the counter pre-set, the
real components are stored past the first N slots, leaving
components[0..N-1] NULL. for_each_rtd_components() stops at the first
NULL entry, so no DAI link component is ever probed on the card.

On Qualcomm Nord RRD board, this shows up as the sound card failing to
bind, as neither the q6apm topology nor the codec widgets get created:

snd-sc8280xp sound: ASoC: Failed to add route VOUT1(*) -> LineOut INL

The same kernel built with GCC 14 works fine, as __flex_counter() is a
no-op there.

Reset num_components to 0 right after allocation, so that the array is
filled from index 0 regardless of the compiler.

Fixes: 4dd10fbbeb9c ("treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj() family")
Signed-off-by: Shawn Guo <shengchao.guo@xxxxxxxxxxxxxxxx>
---
sound/soc/soc-core.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 470c233d97c8..5aab81547157 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -368,6 +368,12 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
return NULL;
}

+ /*
+ * devm_kzalloc_flex() may initialize num_components to the allocated
+ * count, but components[] is filled incrementally by
+ * snd_soc_rtd_add_component(), so start from zero.
+ */
+ rtd->num_components = 0;
rtd->dev = dev;
INIT_LIST_HEAD(&rtd->list);
for_each_pcm_streams(stream) {
--
2.43.0