Re: [PATCH] ALSA: pcm: Serialize snd_pcm_suspend_all() with open_mutex
From: Cássio Gabriel Monteiro Pires
Date: Fri Mar 27 2026 - 08:29:46 EST
On 3/27/26 08:38, Takashi Iwai wrote:
>> walks all PCM substreams and uses a lockless
>> runtime check to skip closed streams. It then calls snd_pcm_suspend()
>> for each remaining substream and finally runs snd_pcm_sync_stop() in a
>> second pass.
>>
>> The runtime lifetime is still controlled by pcm->open_mutex in the
>> open/release path. That means a concurrent close can clear or free
>> substream->runtime after the initial check in snd_pcm_suspend_all(),
>> leaving the later suspend or sync-stop path to dereference a stale or
>> NULL runtime pointer.
>>
>> Serialize snd_pcm_suspend_all() with pcm->open_mutex so the runtime
>> pointer stays stable across both loops. This matches the existing PCM
>> runtime lifetime rule already used by other core paths that access
>> substream->runtime outside the stream lock.
>>
>> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@xxxxxxxxx>
> I guess it's safe to take open_mutex from this function, but it's
> still worth to mention it in the function description.
> Could you update the description of snd_pcm_suspend_all(), too?
>
Yes, I'll do it and send the v2 patch.
--
Thanks,
Cássio