Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: hdmi-codec: Clear the parsed ELD on unplug
@ 2026-11-26 10:37 Roy
  2026-11-26 10:43 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Roy @ 2026-11-26 10:37 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Dmitry Baryshkov, linux-sound,
	linux-kernel, Roy

When the sink goes away, plugged_cb() clears the raw ELD but leaves
hcp->eld_parsed as it was. The eld#N procfs file prints eld_parsed, so
after an unplug it keeps showing the monitor that was last connected
until something is plugged in again.

On a Raspberry Pi 5 (vc4 HDMI), forcing the connector off through
/sys/class/drm/card1-HDMI-A-1/status leaves /proc/asound/card0/eld#0
at:

  monitor_name		WaveShare
  eld_version		[0x2] CEA-861D or below
  sad_count		1

Clear eld_parsed together with the raw ELD, as hdmi_codec_startup()
already does when it finds an empty ELD. eld_parsed is only used for the
procfs file and the log message in plugged_cb(), so nothing else
changes.

Tested on a Raspberry Pi 5 (Raspberry Pi OS kernel 6.18.39, with this
change applied to its snd-soc-hdmi-codec module), forcing HDMI-A-1 off
and back on twice:
- before: eld#0 still shows WaveShare after each unplug
- after: eld#0 shows an empty ELD (eld_version [0x0], sad_count 0) after
  each unplug and WaveShare again after each replug
- HDMI audio playback still works

This change and its description were written with the help of an AI
coding assistant (Claude); the testing above was done on real hardware.

Fixes: 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs")
Signed-off-by: Roy <rongh7426@gmail.com>
---
 sound/soc/codecs/hdmi-codec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index bc59da2..ff4fa9f 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -973,6 +973,7 @@ static void plugged_cb(struct device *dev, bool plugged)
 	} else {
 		hdmi_codec_jack_report(hcp, 0);
 		memset(hcp->eld, 0, sizeof(hcp->eld));
+		memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed));
 	}
 }
 
-- 
2.51.1.windows.1


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

* Re: [PATCH] ASoC: hdmi-codec: Clear the parsed ELD on unplug
  2026-11-26 10:37 [PATCH] ASoC: hdmi-codec: Clear the parsed ELD on unplug Roy
@ 2026-11-26 10:43 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 10:43 UTC (permalink / raw)
  To: Roy; +Cc: linux-sound

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] ASoC: hdmi-codec: data races in ELD structures handling [1]
--

commit b249243bd16fd50e607cc3aaff9399c455c37747
Author: Roy <rongh7426@gmail.com>

ASoC: hdmi-codec: Clear the parsed ELD on unplug

This commit clears hcp->eld_parsed in plugged_cb() when an HDMI sink is
unplugged so that the eld#N procfs file does not report stale monitor data.

> diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
> index bc59da295370c..ff4fa9fbbf68c 100644
> --- a/sound/soc/codecs/hdmi-codec.c
> +++ b/sound/soc/codecs/hdmi-codec.c
> @@ -973,6 +973,7 @@ static void plugged_cb(struct device *dev, bool plugged)
>  	} else {
>  		hdmi_codec_jack_report(hcp, 0);
>  		memset(hcp->eld, 0, sizeof(hcp->eld));
> +		memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed));
>  	}
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can plugged_cb() race with
hdmi_codec_startup(), print_eld_info(), and hdmi_eld_ctl_get() on hcp->eld
and hcp->eld_parsed [1]?

plugged_cb() updates and clears both ELD structures without holding
hcp->lock, while hdmi_codec_startup() mutates them under hcp->lock:

CPU0                                CPU1
plugged_cb()                        hdmi_codec_startup()
                                      guard(mutex)(&hcp->lock);
  hcp->hcd.ops->get_eld(...)          hcp->hcd.ops->get_eld(...)
  snd_parse_eld(...)                  snd_parse_eld(...)  <-- data race

print_eld_info() and hdmi_eld_ctl_get() also read hcp->eld_parsed and
hcp->eld without acquiring hcp->lock, so a concurrent hotplug event can
expose partially updated ELD state (such as a non-zero sad_count before the
SAD array is populated or while it is being zeroed) and corrupt procfs or
ALSA control output.

[1] https://sashiko.dev/#/bug/linux-80b0f2ca-0e91-4822-89fb-4074f7b4e06b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126103757.655758-1-rongh7426@gmail.com?part=1

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

end of thread, other threads:[~2026-11-26 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 10:37 [PATCH] ASoC: hdmi-codec: Clear the parsed ELD on unplug Roy
2026-11-26 10:43 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox