Skip to content

Commit 722cbbf

Browse files
plbossartbroonie
authored andcommitted
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: #3151 Co-developed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Rander Wang <rander.wang@intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20220421203201.1550328-13-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 23b1944 commit 722cbbf

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

sound/soc/sof/intel/hda-dai.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
230230
return -EINVAL;
231231

232232
dev_dbg(cpu_dai->dev, "%s: cmd=%d\n", __func__, cmd);
233+
if (!hext_stream)
234+
return 0;
235+
233236
switch (cmd) {
234237
case SNDRV_PCM_TRIGGER_START:
235238
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -243,8 +246,10 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
243246
stream_tag = hdac_stream(hext_stream)->stream_tag;
244247
snd_hdac_ext_link_clear_stream_id(link, stream_tag);
245248
}
246-
249+
snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
250+
snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
247251
hext_stream->link_prepared = 0;
252+
248253
break;
249254
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
250255
snd_hdac_ext_link_stream_clear(hext_stream);
@@ -370,7 +375,7 @@ static int ipc3_hda_dai_prepare(struct snd_pcm_substream *substream,
370375
int stream = substream->stream;
371376
int ret;
372377

373-
if (hext_stream->link_prepared)
378+
if (hext_stream && hext_stream->link_prepared)
374379
return 0;
375380

376381
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)
460465

461466
/* set internal flag for BE */
462467
list_for_each_entry(s, &bus->stream_list, list) {
468+
struct sof_intel_hda_stream *hda_stream;
469+
463470
hext_stream = stream_to_hdac_ext_stream(s);
464471

465472
/*
@@ -489,13 +496,20 @@ static int hda_dai_suspend(struct hdac_bus *bus)
489496
stream_tag = hdac_stream(hext_stream)->stream_tag;
490497
snd_hdac_ext_link_clear_stream_id(link, stream_tag);
491498
}
499+
snd_soc_dai_set_dma_data(cpu_dai, hext_stream->link_substream, NULL);
500+
snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
492501
hext_stream->link_prepared = 0;
493502

503+
/* free the host DMA channel reserved by hostless streams */
504+
hda_stream = hstream_to_sof_hda_stream(hext_stream);
505+
hda_stream->host_reserved = 0;
506+
494507
/* for consistency with TRIGGER_SUSPEND we free DAI resources */
495508
ret = hda_dai_hw_free_ipc(hdac_stream(hext_stream)->direction, cpu_dai);
496509
if (ret < 0)
497510
return ret;
498511
}
512+
499513
}
500514

501515
return 0;

0 commit comments

Comments
 (0)