Re: [PATCH 5.10 070/491] ASoC: core: Exit all links before removing their components

Cezary Rojewski
2026-04-15T09:01:27Z

On 2026-04-15 12:15 AM, Ben Hutchings wrote:
> On Mon, 2026-04-13 at 17:55 +0200, Greg Kroah-Hartman wrote:
>> 5.10-stable review patch. If anyone has any objections, please let me know.

...

>> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
>> index 4294206dff362..562fbc0fb3475 100644
>> --- a/sound/soc/soc-core.c
>> +++ b/sound/soc/soc-core.c
>> @@ -962,9 +962,6 @@ void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
>>
>> lockdep_assert_held(&client_mutex);
>>
>> - /* release machine specific resources */
>> - snd_soc_link_exit(rtd);
>> -
>> /*
>> * Notify the machine driver for extra destruction
>> */
>
> snd_soc_remove_pcm_runtime() is called from remove_link() in
> soc-topology.c. I might be misunderstanding it, but it seems to free
> the structure that snd_soc_link_exit() accesses immediately after
> snd_soc_remove_pcm_runtime() returns.

Hello Ben,

Good questions all around. Now, the topology is typically loaded during
ASoC's component->probe() and removed during component->remove().
FrontEnd (FE) DAIs spawned during the topology-load process shall be
removed during topology-remove process, so component->remove(). That
remove() is the last third step - after rtd->exit()s and dai->remove()s
and just before the general snd_soc_remove_pcm_runtime().

rtds->exit()
dais->remove()
components->remove()
|_snd_soc_tplg_component_remove()
|__snd_soc_remove_pcm_runtime() // rtds spawned with tplg
snd_soc_remove_pcm_runtime() // rtds spawned without tplg

>
>> @@ -1928,6 +1925,9 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
>>
>> snd_soc_dapm_shutdown(card);
>>
>> + /* release machine specific resources */
>> + for_each_card_rtds(card, rtd)
>> + snd_soc_link_exit(rtd);
>> /* remove and free each DAI */
>> soc_remove_link_dais(card);
>> soc_remove_link_components(card);
>
> So it wouldn't be safe to defer snd_soc_link_exit() to here.
>
> After ff9226224437 ("ASoC: topology: Change allocations to resource
> managed") upstream that memory is device-managed, making the lifetime of
> the link structure long enough for this to be OK. So none of the newer
> branches would have this problem.

In essence, the patch fixes the teardown sequence of a card so that it
matches its startup equivalent. For simplicity, component marked as
(A), DAI with (B) and rtd with (C).

Existing v5.10 startup flow:
(A) -> (B) -> (C)

the teardown:
(B) -> (A) -> (C)

assuming we have an ASoC sound cards with components/DAIs/rtds utilizing
their custom probing procedures, it's clear that one may hit unexpected
issues when tearing down the card. Code implementing rtd->exit() shall
be able to touch the component its paired with.

Let me know if I'm missing something. Perhaps v5.10 has more modprobe
<> rmmod related problems and that's why you're hitting an obstacle.

Kind regards,
Czarek