mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] ALSA: hda: Make hdac_device.registered a plain bool
Date: Wed,  7 Oct 2026 23:56:48 +0200	[thread overview]
Message-ID: <20261007215650.159871-4-tiwai@suse.de> (raw)
In-Reply-To: <20261007215650.159871-1-tiwai@suse.de>

The registered field of hdac_device is a bitfield sharing the same
word with other bitfields like lazy_cache, and those are updated in a
non-atomic read-modify-write manner without any lock.  Meanwhile, the
registered flag is read from the unsolicited event worker
concurrently, so the concurrent updates of the neighboring bitfields
may race with it.

Convert it to a plain bool for avoiding such a subtle race.  Also
replace the assignments of 0/1 with false/true accordingly.

Assisted-by: LLM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/hdaudio.h  | 2 +-
 sound/hda/common/codec.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index 285f7c4d262d..04fd4794bcee 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -96,7 +96,7 @@ struct hdac_device {
 	bool lazy_cache:1;	/* don't wake up for writes */
 	bool caps_overwriting:1; /* caps overwrite being in process */
 	bool cache_coef:1;	/* cache COEF read/write too */
-	unsigned int registered:1; /* codec was registered */
+	bool registered;	/* codec was registered */
 	bool unsol_disabled;	/* unsol events blocked; protected by bus->reg_lock */
 };
 
diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index b79346d01021..c99fe61c29db 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -761,7 +761,7 @@ 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));
-		codec->core.registered = 0;
+		codec->core.registered = false;
 	}
 
 	snd_hda_codec_disconnect_pcms(codec);
@@ -815,7 +815,7 @@ 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);
-		codec->core.registered = 1;
+		codec->core.registered = true;
 	}
 }
 EXPORT_SYMBOL_GPL(snd_hda_codec_register);
-- 
2.55.0


      parent reply	other threads:[~2026-10-07 21:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 21:56 [PATCH 0/3] ALSA/ASoC: hda: Fix race between unsol events and unbind Takashi Iwai
2026-10-07 21:56 ` [PATCH 1/3] ALSA: hda: Stop unsol events and jack polling before codec unbind Takashi Iwai
2026-10-08  9:08   ` Cezary Rojewski
2026-10-08 10:16     ` Takashi Iwai
2026-10-08 11:52       ` Cezary Rojewski
2026-10-08 12:01         ` Takashi Iwai
2026-10-07 21:56 ` [PATCH 2/3] ASoC: codecs: hda: Stop unsol events and jack polling before codec removal Takashi Iwai
2026-10-07 21:56 ` Takashi Iwai [this message]

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=20261007215650.159871-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®