--- /dev/null
+From 1f810d2b6b2fbdc5279644d8b2c140b1f7c9d43d Mon Sep 17 00:00:00 2001
+From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
+Date: Thu, 16 Feb 2023 18:23:40 +0200
+Subject: ASoC: SOF: Intel: hda-dai: fix possible stream_tag leak
+
+From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
+
+commit 1f810d2b6b2fbdc5279644d8b2c140b1f7c9d43d upstream.
+
+The HDaudio stream allocation is done first, and in a second step the
+LOSIDV parameter is programmed for the multi-link used by a codec.
+
+This leads to a possible stream_tag leak, e.g. if a DisplayAudio link
+is not used. This would happen when a non-Intel graphics card is used
+and userspace unconditionally uses the Intel Display Audio PCMs without
+checking if they are connected to a receiver with jack controls.
+
+We should first check that there is a valid multi-link entry to
+configure before allocating a stream_tag. This change aligns the
+dma_assign and dma_cleanup phases.
+
+Complements: b0cd60f3e9f5 ("ALSA/ASoC: hda: clarify bus_get_link() and bus_link_get() helpers")
+Link: https://github.com/thesofproject/linux/issues/4151
+Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
+Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
+Reviewed-by: Rander Wang <rander.wang@intel.com>
+Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
+Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
+Link: https://lore.kernel.org/r/20230216162340.19480-1-peter.ujfalusi@linux.intel.com
+Signed-off-by: Mark Brown <broonie@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ sound/soc/sof/intel/hda-dai.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+--- a/sound/soc/sof/intel/hda-dai.c
++++ b/sound/soc/sof/intel/hda-dai.c
+@@ -216,6 +216,10 @@ static int hda_link_dma_hw_params(struct
+ struct hdac_bus *bus = hstream->bus;
+ struct hdac_ext_link *link;
+
++ link = snd_hdac_ext_bus_get_link(bus, codec_dai->component->name);
++ if (!link)
++ return -EINVAL;
++
+ hext_stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
+ if (!hext_stream) {
+ hext_stream = hda_link_stream_assign(bus, substream);
+@@ -225,10 +229,6 @@ static int hda_link_dma_hw_params(struct
+ snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)hext_stream);
+ }
+
+- link = snd_hdac_ext_bus_get_link(bus, codec_dai->component->name);
+- if (!link)
+- return -EINVAL;
+-
+ /* set the hdac_stream in the codec dai */
+ snd_soc_dai_set_stream(codec_dai, hdac_stream(hext_stream), substream->stream);
+