RE: [PATCH] ASoC: soc-core: reset rtd->num_components after allocation
From: Cosmin-Gabriel Tanislav
Date: Wed Nov 11 2026 - 07:34:36 EST
> From: Emanuele Ghidoli <ghidoliemanuele@xxxxxxxxx>
> Sent: Monday, November 9, 2026 12:25 PM
>
> Commit 4dd10fbbeb9c ("treewide: Convert devm_kmalloc() family to the
> devm_kmalloc_obj() family") switched the snd_soc_pcm_runtime allocation
> in soc_new_pcm_runtime() to devm_kzalloc_flex(). components[] is
> annotated with __counted_by(num_components), so when the compiler
> provides __builtin_counted_by_ref() the allocation now also sets
> rtd->num_components to the number of allocated slots.
>
> snd_soc_rtd_add_component() fills components[] one entry at a time and
> expects num_components to start at zero. Starting from the allocated
> size, for_each_rtd_components() stops at the first, still NULL, entry,
> so the runtime has no components: they are not probed, no controls or
> user-visible PCM devices are created and the card registers empty,
> without any error message. In addition, each added component is stored
> past the end of components[]. On the tested board these stores still
> land in the slack of the kmalloc bucket that devres rounds the
> allocation up to, so KASAN does not report them.
>
> Reset num_components after the allocation.
>
> Seen on a Colibri iMX7D (simple-audio-card, fsl-sai, sgtl5000): the card
> is listed in /proc/asound/cards, but /proc/asound/pcm is empty and
>
> amixer: Unable to find simple control 'Capture Mux',0
> aplay: main:850: audio open error: No such file or directory
>
> Tested on that board with v7.4-rc2 built with GCC 15.2 (first seen with
> GCC 16.2): the failure is there without this change; with it, playback,
> capture and the codec controls work again.
>
> The root cause analysis, this change and the testing were done with the
> help of an AI coding assistant (Claude Code, Claude Opus 5.5).
>
> Fixes: 4dd10fbbeb9c ("treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj() family")
> Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@xxxxxxxxxxx>
We also hit the same bug on several of our SoCs, although with different
symptoms.
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000060
Hardware name: HopeRun HiHope RZ/G2H with sub board (DT)
Workqueue: events_unbound deferred_probe_work_func
pc : mutex_lock+0x20/0x4c
lr : snd_soc_dapm_add_routes+0x28/0xa0
Call trace:
mutex_lock+0x20/0x4c (P)
hdmi_dai_probe+0xa4/0x1d0
snd_soc_pcm_dai_probe+0x64/0xdc
snd_soc_card_bind+0x568/0xb60
snd_soc_card_bind_call+0x64/0xd0
snd_soc_register_card+0xcc/0x100
devm_snd_soc_register_card+0x14/0x20
audio_graph_parse_of+0x228/0x2dc
graph_probe+0x7c/0x94
With this patch applied on top of next-20261110, RZ/G2H, RZ/G2M, RZ/G2N,
RZ/G2L and RZ/V2L no longer hit a NULL pointer dereference in
hdmi_dai_probe() and the sound cards now register properly.
Tested-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@xxxxxxxxxxx>