[PATCH 2/3] ALSA: hda: split the lock_devices pseudo-lock from card->shutdown
From: Hanxiang Xu
Date: Tue Dec 01 2026 - 22:02:02 EST
snd_hda_lock_devices()/snd_hda_unlock_devices() reuse card->shutdown
as a reversible pseudo-lock while a codec reconfiguration detaches the
codec driver. A PCI unbind entering snd_card_free() inside that
window gets snd_card_disconnect() skipped entirely (the minors stay
registered and snd_cards[] stays populated), and then blocks forever
in snd_card_free()'s wait_for_completion(): the completion is only
fired from snd_card_do_free(), which needs the card reference count to
reach zero, and the outstanding minor references prevent that.
Track the pseudo-lock in a separate card->pseudo_locked flag so that
snd_card_disconnect() keeps performing a real teardown while the
driver is detached; the flag stays protected by card->files_lock.
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
---
include/sound/core.h | 1 +
sound/hda/common/codec.c | 8 +++++---
diff --git a/include/sound/core.h b/include/sound/core.h
index d658496..b3ab6a8 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -140,6 +140,7 @@
state */
spinlock_t files_lock; /* lock the files for this card */
int shutdown; /* this card is going down */
+ bool pseudo_locked; /* hda pseudo device lock */
struct completion *release_completion;
struct device *dev; /* device assigned to this card */
struct device card_dev; /* cardX object for sysfs */
diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index e367cc1..d8af9cc 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -1758,7 +1758,9 @@
guard(spinlock)(&card->files_lock);
if (card->shutdown)
return -EINVAL;
- card->shutdown = 1;
+ if (card->pseudo_locked)
+ return -EINVAL;
+ card->pseudo_locked = 1;
if (!list_empty(&card->ctl_files))
goto err_clear;
@@ -1775,7 +1777,7 @@
return 0;
err_clear:
- card->shutdown = 0;
+ card->pseudo_locked = 0;
return -EINVAL;
}
EXPORT_SYMBOL_GPL(snd_hda_lock_devices);
@@ -1789,7 +1791,7 @@
struct snd_card *card = bus->card;
guard(spinlock)(&card->files_lock);
- card->shutdown = 0;
+ card->pseudo_locked = 0;
}
EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
--
2.43.0