Re: [PATCH v2 2/2] ASoC: hdmi-codec: Hold the lock while the ELD is updated or read

From: Mark Brown

Date: Fri Dec 04 2026 - 13:30:12 EST


> 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.

> @@ -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);

There's also other readers, in hdmi_codec_startup() we pass a pointer to
snd_pcm_hw_constraint_eld() which stores it and then causes it to get
parsed during later params handling. We should probably take a snapshot
before handing over as constraints or something. OTOH that's a
preexisting issue and this closes a bunch of the races which you were
actually able to trigger so probably we can fix that incrementally.

--
Mark Brown <broonie@xxxxxxxxxx>