Skip to content

Commit

Permalink
ASoC: SOF: Intel: hda-dai: reset dma_data and release stream
Browse files Browse the repository at this point in the history
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: thesofproject#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>
  • Loading branch information
plbossart committed Oct 7, 2021
1 parent febeb85 commit b36a481
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions sound/soc/sof/intel/hda-dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static int hda_dai_link_prepare(struct snd_pcm_substream *substream)
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(cpu_dai->component);
int stream = substream->stream;

if (he_stream->link_prepared)
if (he_stream && he_stream->link_prepared)
return 0;

dev_dbg(sdev->dev, "%s: prepare stream dir %d\n", __func__, substream->stream);
Expand All @@ -232,6 +232,9 @@ static int hda_dai_link_trigger(struct snd_pcm_substream *substream, int cmd)
return -EINVAL;

dev_dbg(cpu_dai->dev, "%s: cmd=%d\n", __func__, cmd);
if (!he_stream)
return 0;

switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Expand All @@ -243,7 +246,8 @@ static int hda_dai_link_trigger(struct snd_pcm_substream *substream, int cmd)
stream_tag = hdac_stream(he_stream)->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(he_stream, HDAC_EXT_STREAM_TYPE_LINK);
he_stream->link_prepared = 0;

fallthrough;
Expand Down Expand Up @@ -466,6 +470,8 @@ static int hda_dai_suspend(struct hdac_bus *bus)

/* set internal flag for BE */
list_for_each_entry(s, &bus->stream_list, list) {
struct sof_intel_hda_stream *hda_stream;

he_stream = stream_to_hdac_ext_stream(s);

if (!he_stream)
Expand Down Expand Up @@ -493,7 +499,8 @@ static int hda_dai_suspend(struct hdac_bus *bus)
stream_tag = hdac_stream(he_stream)->stream_tag;
snd_hdac_ext_link_clear_stream_id(link, stream_tag);
}

snd_soc_dai_set_dma_data(cpu_dai, he_stream->link_substream, NULL);
snd_hdac_ext_stream_release(he_stream, HDAC_EXT_STREAM_TYPE_LINK);
he_stream->link_prepared = 0;

/*
Expand All @@ -507,6 +514,10 @@ static int hda_dai_suspend(struct hdac_bus *bus)
if (ret < 0)
return ret;
}

/* free the host DMA channel reserved by hostless streams */
hda_stream = hstream_to_sof_hda_stream(he_stream);
hda_stream->host_reserved = 0;
}

return 0;
Expand Down

0 comments on commit b36a481

Please sign in to comment.