From: Roy <rongh7426@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Dmitry Baryshkov <lumag@kernel.org>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Roy <rongh7426@gmail.com>
Subject: [PATCH] ASoC: hdmi-codec: Hold the lock while the ELD is updated or read
Date: Sun, 29 Nov 2026 16:33:29 +0800 [thread overview]
Message-ID: <20261129083329.786322-1-rongh7426@gmail.com> (raw)
plugged_cb() rewrites hcp->eld and hcp->eld_parsed without taking
hcp->lock, while the ELD control, the ELD proc file and hw_params read
them without it too. Only startup() takes the lock. A reader that runs
during a hotplug can see a half-copied or half-cleared ELD.
On a Raspberry Pi 5 (vc4) I toggled the connector between forced off
and on while reading the ELD control in a loop. In 120 seconds 3 of
about 266 million reads returned an ELD that was neither the monitor's
nor all zero: the header copied and the rest still zero, or the first
16 bytes cleared and the monitor name still there.
Take hcp->lock around the ELD update in plugged_cb() and around the
readers. None of the drivers that call plugged_cb() take a lock that
startup() also takes under hcp->lock, so this adds no lock inversion.
With this patch the same test gave no torn reads in about 255 million
reads, and repeated playback during hotplug still worked with no hung
tasks. Tested as an out-of-tree module on 6.18.39.
The problem was found by the sashiko review bot, and the patch was
written with the help of an AI coding assistant (Claude). I reproduced
it, tested it on hardware and reviewed the change.
Fixes: 25ce4f2b3593 ("ASoC: hdmi-codec: Get ELD in before reporting plugged event")
Fixes: 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs")
Signed-off-by: Roy <rongh7426@gmail.com>
---
Notes:
This applies on top of my earlier patch "ASoC: hdmi-codec: Clear the parsed ELD
on unplug":
https://lore.kernel.org/all/20261126103757.655758-1-rongh7426@gmail.com/
sound/soc/codecs/hdmi-codec.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index ff4fa9f..b1b1926 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -318,6 +318,7 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
+ guard(mutex)(&hcp->lock);
memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld));
return 0;
@@ -526,7 +527,8 @@ static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai,
if (pcm_audio) {
/* Select a channel allocation that matches with ELD and pcm channels */
- idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
+ scoped_guard(mutex, &hcp->lock)
+ idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
if (idx < 0) {
dev_err(dai->dev, "Not able to map channels to speakers (%d)\n",
@@ -841,6 +843,7 @@ static void print_eld_info(struct snd_info_entry *entry,
{
struct hdmi_codec_priv *hcp = entry->private_data;
+ guard(mutex)(&hcp->lock);
snd_print_eld_info(&hcp->eld_parsed, buffer);
}
@@ -960,6 +963,7 @@ static void plugged_cb(struct device *dev, bool plugged)
if (plugged) {
if (hcp->hcd.ops->get_eld) {
+ guard(mutex)(&hcp->lock);
hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data,
hcp->eld, sizeof(hcp->eld));
ret = snd_parse_eld(dev, &hcp->eld_parsed,
@@ -972,6 +976,7 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, SND_JACK_AVOUT);
} else {
hdmi_codec_jack_report(hcp, 0);
+ guard(mutex)(&hcp->lock);
memset(hcp->eld, 0, sizeof(hcp->eld));
memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed));
}
--
2.51.1.windows.1
reply other threads:[~2026-11-29 8:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261129083329.786322-1-rongh7426@gmail.com \
--to=rongh7426@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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®