mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org, tiwai@suse.de,
	baijiaju1990@gmail.com, jjzuming@gmail.com
Subject: Re: [PATCH v3] ALSA: pcm: Drain proc callbacks at device disconnect
Date: Fri, 23 Oct 2026 15:40:40 +0200	[thread overview]
Message-ID: <87cxt0a61z.wl-tiwai@suse.de> (raw)
In-Reply-To: <pm-pmb-2439c851f82c443c3600-v7-2774a482b7f03e1fef60@gmail.com>

On Thu, 22 Oct 2026 12:58:20 +0200,
Cen Zhang wrote:
> 
> Disconnecting an individual PCM leaves its proc files accessible until
> snd_pcm_free_stream(). HDA codec-only sysfs unbind can take this path
> while the controller and card remain registered. An open proc file pins
> the card module, but does not hold a codec PCM reference.
> 
> With CONFIG_SND_VERBOSE_PROCFS, a prealloc write is buffered until file
> release. Without an attached PCM runtime, its release can replace the
> DMA buffer after final PCM cleanup has already freed the preallocation:
> 
>   HDA codec unbind                  prealloc file release
>   ----------------                  ---------------------
>   hda_codec_driver_remove()
>     snd_hda_codec_disconnect_pcms()
>       snd_device_disconnect()
>         snd_pcm_dev_disconnect()
>         /* proc nodes remain */
>     snd_hda_codec_cleanup_for_unbind()
>       codec_release_pcms()
>         snd_device_free()
>           snd_pcm_free()
>             free preallocated buffer
>                                     snd_info_text_entry_release()
>                                       snd_pcm_lib_preallocate_proc_write()
>                                         replace DMA buffer
>             remove stream proc nodes
>             free substream
> 
> The later proc rundown can itself invoke this buffered write and leave
> the replacement allocation without a final free. A concurrent release
> can also overlap the earlier buffer cleanup.
> 
> Extract snd_info_disconnect_entry() from snd_info_free_entry() to remove
> proc nodes and drain callbacks without freeing the info entry objects.
> Use it for both stream directions at PCM disconnect. Finish the existing
> PCM state and device disconnection under open_mutex, then drop that lock
> before proc rundown: even an otherwise idle proc file can run its
> buffered release callback, which takes open_mutex, during proc_remove().
> 
> Keep entry ownership and final cleanup unchanged, including the saved
> OSS child entries. As with existing info entry teardown, callers must
> serialize registration with disconnection and release.
> 
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Assisted-by: LLM
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

Applied now.  Although we still may have some issues about the
concurrent codec release and probe, this should be treated better in
the upper layer.


thanks,

Takashi

      reply	other threads:[~2026-10-23 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 10:58 Cen Zhang
2026-10-23 13:40 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cxt0a61z.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=baijiaju1990@gmail.com \
    --cc=jjzuming@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=zzzccc427@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®