From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/5] ALSA: hda: Add lock around codec->registered flag manipulations
Date: Fri, 9 Oct 2026 15:33:37 +0200 [thread overview]
Message-ID: <20261009133341.440917-4-tiwai@suse.de> (raw)
In-Reply-To: <20261009133341.440917-1-tiwai@suse.de>
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@suse.de>
---
v1->v2: fix build error
sound/hda/common/codec.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index 94da4f3a21ed..18838a45e6f7 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -757,11 +757,15 @@ static void codec_release_pcms(struct hda_codec *codec)
*/
void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
{
+ struct hda_bus *bus = codec->bus;
+
if (codec->core.registered) {
/* 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->core.reg_lock);
codec->core.registered = false;
+ spin_unlock_irq(&bus->core.reg_lock);
}
snd_hda_codec_disconnect_pcms(codec);
@@ -808,6 +812,8 @@ void snd_hda_codec_display_power(struct hda_codec *codec, bool enable)
*/
void snd_hda_codec_register(struct hda_codec *codec)
{
+ struct hda_bus *bus = codec->bus;
+
if (codec->core.registered)
return;
if (device_is_registered(hda_codec_dev(codec))) {
@@ -815,7 +821,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->core.reg_lock);
codec->core.registered = true;
+ spin_unlock_irq(&bus->core.reg_lock);
}
}
EXPORT_SYMBOL_GPL(snd_hda_codec_register);
--
2.55.0
next prev parent reply other threads:[~2026-10-09 13:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 13:33 [PATCH v2 0/5] ALSA: yet a few more fixes for AI bug reports Takashi Iwai
2026-10-09 13:33 ` [PATCH v2 1/5] ALSA: line6: Fix handling of zero-length capture packets Takashi Iwai
2026-10-10 8:04 ` Takashi Iwai
2026-10-09 13:33 ` [PATCH v2 2/5] ALSA: hda: Disable unsol event handling at error and shutdown paths Takashi Iwai
2026-10-09 13:33 ` Takashi Iwai [this message]
2026-10-09 13:33 ` [PATCH v2 4/5] ALSA: hda: Stop unsol event and jack polling at hda-ext device removal, too Takashi Iwai
2026-10-09 13:33 ` [PATCH v2 5/5] ALSA: hda: Add NULL check for the driver pointer at unsol event work Takashi Iwai
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=20261009133341.440917-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
/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®