[PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations

From: Takashi Iwai

Date: Thu Oct 08 2026 - 15:29:54 EST


Currently the places setting or clearing codec->registered flag have
no locking, while its reference in the unsol handling work
snd_hdac_bus_process_unsol_events() takes the bus->reg_lock lock.
Let's add the same bus->reg_lock at the places where codec->registered
is set and cleared for avoiding the races.

Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
sound/hda/common/codec.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index 94da4f3a21ed..7fbced571282 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -761,7 +761,9 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
/* pm_runtime_put() is called in snd_hdac_device_exit() */
pm_runtime_get_noresume(hda_codec_dev(codec));
pm_runtime_disable(hda_codec_dev(codec));
+ spin_lock_irq(&bus->reg_lock);
codec->core.registered = false;
+ spin_unlock_irq(&bus->reg_lock);
}

snd_hda_codec_disconnect_pcms(codec);
@@ -815,7 +817,9 @@ void snd_hda_codec_register(struct hda_codec *codec)
pm_runtime_enable(hda_codec_dev(codec));
/* it was powered up in snd_hda_codec_new(), now all done */
snd_hda_power_down(codec);
+ spin_lock_irq(&bus->reg_lock);
codec->core.registered = true;
+ spin_unlock_irq(&bus->reg_lock);
}
}
EXPORT_SYMBOL_GPL(snd_hda_codec_register);
--
2.55.0