Re: [PATCH] ALSA: pcm: Drain proc writers before freeing preallocated buffers
From: Cen Zhang
Date: Thu Oct 22 2026 - 05:02:10 EST
Hi Takashi,
Takashi Iwai <tiwai@xxxxxxx> 于2026年10月20日周二 16:40写道:
>
> I believe a better fix is to handle the disconnection of procfs more
> properly. The hda codec driver calls snd_device_disconnect() for each
> pcm, but in the PCM side, the procfs removal relies on the card level
> disconnection (snd_info_card_disconnect()).
>
> That is, something like below works instead?
>
>
> thanks,
>
> Takashi
>
> --- a/sound/core/pcm.c
> +++ b/sound/core/pcm.c
> @@ -1119,6 +1119,7 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
> for (cidx = 0; cidx < 2; cidx++) {
> if (pcm->streams[cidx].dev)
> snd_unregister_device(pcm->streams[cidx].dev);
> + snd_pcm_stream_proc_done(&pcm->streams[cidx]);
> free_chmap(&pcm->streams[cidx]);
> }
> return 0;
>
Sorry for the delayed reply — something came up to me over the past
few days.
Thanks for the review. Handling the proc entries at PCM disconnect
looks like a better approach.But I noticed two possible issues with
adding the call here: proc removal can invoke a prealloc release
callback that takes open_mutex, which is already held; freeing the
subtree also leaves pstr->oss.proc_entry pointing to freed storage
until final unregister.
I'll follow your approach, but perform proc rundown outside open_mutex
and retain the entry objects until final cleanup. I'll also prevent subsequent
card registration from republishing the disconnected entries.
Best regards,
Cen Zhang