Commit 722cbbfa authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Mark Brown

ASoC: SOF: Intel: hda-dai: reset dma_data and release stream

The sequences are missing a call to snd_soc_dai_set_dma_data() when
the stream is cleared, as well as a release of the stream, and tests
to avoid pointer dereferences.

This fixes an underflow issue in a corner case with two streams paused
before a suspend-resume cycle. After resume, the pause_release of the
last stream causes an underflow due to an invalid sequence.

This problem probably existed since the beginning and is only see with
prototypes of a 'deep-buffer' capability, which depends on additional
ASoC fixes, so there's is no Fixes: tag and no real requirement to
backport this patch.

BugLink: https://github.com/thesofproject/linux/issues/3151Co-developed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarRander Wang <rander.wang@intel.com>
Reviewed-by: default avatarPéter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20220421203201.1550328-13-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 23b1944e
...@@ -230,6 +230,9 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd) ...@@ -230,6 +230,9 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
return -EINVAL; return -EINVAL;
dev_dbg(cpu_dai->dev, "%s: cmd=%d\n", __func__, cmd); dev_dbg(cpu_dai->dev, "%s: cmd=%d\n", __func__, cmd);
if (!hext_stream)
return 0;
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
...@@ -243,8 +246,10 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd) ...@@ -243,8 +246,10 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
stream_tag = hdac_stream(hext_stream)->stream_tag; stream_tag = hdac_stream(hext_stream)->stream_tag;
snd_hdac_ext_link_clear_stream_id(link, stream_tag); snd_hdac_ext_link_clear_stream_id(link, stream_tag);
} }
snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
hext_stream->link_prepared = 0; hext_stream->link_prepared = 0;
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
snd_hdac_ext_link_stream_clear(hext_stream); snd_hdac_ext_link_stream_clear(hext_stream);
...@@ -370,7 +375,7 @@ static int ipc3_hda_dai_prepare(struct snd_pcm_substream *substream, ...@@ -370,7 +375,7 @@ static int ipc3_hda_dai_prepare(struct snd_pcm_substream *substream,
int stream = substream->stream; int stream = substream->stream;
int ret; int ret;
if (hext_stream->link_prepared) if (hext_stream && hext_stream->link_prepared)
return 0; return 0;
dev_dbg(sdev->dev, "%s: prepare stream dir %d\n", __func__, substream->stream); dev_dbg(sdev->dev, "%s: prepare stream dir %d\n", __func__, substream->stream);
...@@ -460,6 +465,8 @@ static int hda_dai_suspend(struct hdac_bus *bus) ...@@ -460,6 +465,8 @@ static int hda_dai_suspend(struct hdac_bus *bus)
/* set internal flag for BE */ /* set internal flag for BE */
list_for_each_entry(s, &bus->stream_list, list) { list_for_each_entry(s, &bus->stream_list, list) {
struct sof_intel_hda_stream *hda_stream;
hext_stream = stream_to_hdac_ext_stream(s); hext_stream = stream_to_hdac_ext_stream(s);
/* /*
...@@ -489,13 +496,20 @@ static int hda_dai_suspend(struct hdac_bus *bus) ...@@ -489,13 +496,20 @@ static int hda_dai_suspend(struct hdac_bus *bus)
stream_tag = hdac_stream(hext_stream)->stream_tag; stream_tag = hdac_stream(hext_stream)->stream_tag;
snd_hdac_ext_link_clear_stream_id(link, stream_tag); snd_hdac_ext_link_clear_stream_id(link, stream_tag);
} }
snd_soc_dai_set_dma_data(cpu_dai, hext_stream->link_substream, NULL);
snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
hext_stream->link_prepared = 0; hext_stream->link_prepared = 0;
/* free the host DMA channel reserved by hostless streams */
hda_stream = hstream_to_sof_hda_stream(hext_stream);
hda_stream->host_reserved = 0;
/* for consistency with TRIGGER_SUSPEND we free DAI resources */ /* for consistency with TRIGGER_SUSPEND we free DAI resources */
ret = hda_dai_hw_free_ipc(hdac_stream(hext_stream)->direction, cpu_dai); ret = hda_dai_hw_free_ipc(hdac_stream(hext_stream)->direction, cpu_dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment