All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses
@ 2026-10-27  7:28 Peter Ujfalusi
  2026-10-27  8:11 ` Takashi Iwai
  2026-10-27  9:09 ` Cezary Rojewski
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Ujfalusi @ 2026-10-27  7:28 UTC (permalink / raw)
  To: perex, tiwai
  Cc: pierre-louis.bossart, linux-sound, stable, cezary.rojewski,
	kai.vehmanen

Writing to the reconfig or clear sysfs nodes of a codec handled by ASoC
(SOF via hdac_hda, AVS via codecs/hda) hangs the writer.

snd_hda_codec_reset() sets card->shutdown and calls
device_release_driver(). With ext_ops the driver unbind unregisters the
ASoC component, which unbinds and frees the whole ASoC card:
- snd_card_disconnect() returns early as card->shutdown is already set,
  so the card's child devices are not removed and snd_card_free() waits
  for the card release forever.
- Even without that, freeing the card removes the codec's hwdep device,
  which owns the sysfs node the reset was issued from, deadlocking in
  kernfs while waiting for the active write to finish.

The legacy HDA driver keeps the card across a driver rebind, ASoC does
not, so the reset cannot be supported there. Return -EOPNOTSUPP and skip
the misleading "codec is being used" messages in the callers.

Fixes: 6bae5ea94989 ("ASoC: hdac_hda: add asoc extension for legacy HDA codec drivers")
Cc: stable@vger.kernel.org
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222182
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 sound/hda/common/codec.c | 6 ++++++
 sound/hda/common/sysfs.c | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index 31e5fad78b0f..e367cc1c6e78 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -1807,6 +1807,12 @@ int snd_hda_codec_reset(struct hda_codec *codec)
 {
 	struct hda_bus *bus = codec->bus;
 
+	/* ASoC: driver unbind frees the card, incl. the hwdep issuing the reset */
+	if (bus->core.ext_ops) {
+		codec_err(codec, "Codec reset is not supported with ASoC\n");
+		return -EOPNOTSUPP;
+	}
+
 	if (snd_hda_lock_devices(bus) < 0)
 		return -EBUSY;
 
diff --git a/sound/hda/common/sysfs.c b/sound/hda/common/sysfs.c
index bedf10b30885..bf65223fde10 100644
--- a/sound/hda/common/sysfs.c
+++ b/sound/hda/common/sysfs.c
@@ -117,6 +117,8 @@ static int clear_codec(struct hda_codec *codec)
 	int err;
 
 	err = snd_hda_codec_reset(codec);
+	if (err == -EOPNOTSUPP)
+		return err;
 	if (err < 0) {
 		codec_err(codec, "The codec is being used, can't free.\n");
 		return err;
@@ -132,6 +134,8 @@ static int reconfig_codec(struct hda_codec *codec)
 	CLASS(snd_hda_power, pm)(codec);
 	codec_info(codec, "hda-codec: reconfiguring\n");
 	err = snd_hda_codec_reset(codec);
+	if (err == -EOPNOTSUPP)
+		return err;
 	if (err < 0) {
 		codec_err(codec,
 			   "The codec is being used, can't reconfigure.\n");
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses
  2026-10-27  7:28 [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses Peter Ujfalusi
@ 2026-10-27  8:11 ` Takashi Iwai
  2026-10-27  9:09 ` Cezary Rojewski
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-10-27  8:11 UTC (permalink / raw)
  To: Peter Ujfalusi
  Cc: perex, tiwai, pierre-louis.bossart, linux-sound, stable,
	cezary.rojewski, kai.vehmanen

On Tue, 27 Oct 2026 08:28:35 +0100,
Peter Ujfalusi wrote:
> 
> Writing to the reconfig or clear sysfs nodes of a codec handled by ASoC
> (SOF via hdac_hda, AVS via codecs/hda) hangs the writer.
> 
> snd_hda_codec_reset() sets card->shutdown and calls
> device_release_driver(). With ext_ops the driver unbind unregisters the
> ASoC component, which unbinds and frees the whole ASoC card:
> - snd_card_disconnect() returns early as card->shutdown is already set,
>   so the card's child devices are not removed and snd_card_free() waits
>   for the card release forever.
> - Even without that, freeing the card removes the codec's hwdep device,
>   which owns the sysfs node the reset was issued from, deadlocking in
>   kernfs while waiting for the active write to finish.
> 
> The legacy HDA driver keeps the card across a driver rebind, ASoC does
> not, so the reset cannot be supported there. Return -EOPNOTSUPP and skip
> the misleading "codec is being used" messages in the callers.
> 
> Fixes: 6bae5ea94989 ("ASoC: hdac_hda: add asoc extension for legacy HDA codec drivers")
> Cc: stable@vger.kernel.org
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222182
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

Applied now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses
  2026-10-27  7:28 [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses Peter Ujfalusi
  2026-10-27  8:11 ` Takashi Iwai
@ 2026-10-27  9:09 ` Cezary Rojewski
  1 sibling, 0 replies; 3+ messages in thread
From: Cezary Rojewski @ 2026-10-27  9:09 UTC (permalink / raw)
  To: Peter Ujfalusi, perex, tiwai
  Cc: pierre-louis.bossart, linux-sound, stable, kai.vehmanen

On 10/27/2026 8:28 AM, Peter Ujfalusi wrote:
> Writing to the reconfig or clear sysfs nodes of a codec handled by ASoC
> (SOF via hdac_hda, AVS via codecs/hda) hangs the writer.
> 
> snd_hda_codec_reset() sets card->shutdown and calls
> device_release_driver(). With ext_ops the driver unbind unregisters the
> ASoC component, which unbinds and frees the whole ASoC card:
> - snd_card_disconnect() returns early as card->shutdown is already set,
>   so the card's child devices are not removed and snd_card_free() waits
>   for the card release forever.
> - Even without that, freeing the card removes the codec's hwdep device,
>   which owns the sysfs node the reset was issued from, deadlocking in
>   kernfs while waiting for the active write to finish.
> 
> The legacy HDA driver keeps the card across a driver rebind, ASoC does
> not, so the reset cannot be supported there. Return -EOPNOTSUPP and skip
> the misleading "codec is being used" messages in the callers.
> 
> Fixes: 6bae5ea94989 ("ASoC: hdac_hda: add asoc extension for legacy HDA codec drivers")
> Cc: stable@vger.kernel.org
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222182
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

We've had a short chat about this case and I'm grateful for the quick
resolution. Thanks you Peter!

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-27  9:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27  7:28 [PATCH] ALSA: hda: Reject codec reset on ASoC (ext_ops) buses Peter Ujfalusi
2026-10-27  8:11 ` Takashi Iwai
2026-10-27  9:09 ` Cezary Rojewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.