[PATCH 3/3] ALSA: hda: quiesce the codec at codec-device disconnect

From: Hanxiang Xu

Date: Tue Dec 01 2026 - 22:02:08 EST


The codec poll work is cancelled and the jack table is released only
when the codec driver detaches, which in the card release phase
happens after snd_device_free_all() already freed the JACK devices -
so an in-flight poll work item or jack callback can touch memory that
was freed earlier in the same pass.

Add a .dev_disconnect callback for the codec snd_device that cancels
the poll work, waits out in-flight PCM users and detaches the codec
driver. The quiesce now happens in the disconnect phase, while every
other device on the card is still alive.

Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
---
sound/hda/common/codec.c | 11 +++++++++++

diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index e367cc1..4c25c82 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -834,6 +834,16 @@
return 0;
}

+static int snd_hda_codec_dev_disconnect(struct snd_device *device)
+{
+ struct hda_codec *codec = device->device_data;
+
+ cancel_delayed_work_sync(&codec->jackpoll_work);
+ snd_refcount_sync(&codec->pcm_ref);
+ device_release_driver(hda_codec_dev(codec));
+ return 0;
+}
+
/**
* snd_hda_codec_unregister - Unregister specified codec device
* @codec: codec device to unregister
@@ -977,6 +987,7 @@
int err;
static const struct snd_device_ops dev_ops = {
.dev_register = snd_hda_codec_dev_register,
+ .dev_disconnect = snd_hda_codec_dev_disconnect,
.dev_free = snd_hda_codec_dev_free,
};


--
2.43.0