From bce07ade1ec8e48764a3cbc87c70a36b9fa955d3 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Thu, 26 Nov 2026 17:20:08 +0200 Subject: [PATCH] fixup! ASoC: SOF: pcm/pm: Fix WoV flow during system suspend / resume Note for the squash: amend this to the "Fix WoV flow during system suspend / resume" commit. Extend its commit message with: If the application closes the stream while it is still SUSPENDED, ALSA does not send STOP to it, the pipeline started_count is never decremented, the pipeline RESET is skipped in hw_free and the firmware is asked to unbind running pipelines, which makes the DSP panic. In sof_pcm_stream_free() clear suspend_ignored and replay what was missed, in the order of a regular STOP: RESUME and STOP the BEs via dpcm_be_dai_trigger() (the BEs are in DPCM SUSPEND state while their pipeline and link DMA is still running, the BE pipeline is skipped by the FE trigger), then STOP the FE pipelines. Signed-off-by: Peter Ujfalusi --- sound/soc/sof/pcm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c index 0161c0ae8bbdb4..8936db4646534c 100644 --- a/sound/soc/sof/pcm.c +++ b/sound/soc/sof/pcm.c @@ -215,6 +215,48 @@ static int sof_pcm_stream_free(struct snd_sof_dev *sdev, int ret; int err = 0; + /* + * A WoV stream that ignored the system suspend has its pipelines still + * running in the firmware. ALSA does not send STOP to a SUSPENDED stream + * before hw_free/prepare, so stop the pipelines here to get the + * started/paused bookkeeping in order. Otherwise the pipeline RESET is + * skipped and the firmware gets asked to unbind a running pipeline. + * + * The BEs also ignored the suspend: DPCM considers them SUSPENDED while + * their pipeline (and link DMA) is still running. Replay what the stack + * missed in the same order as a regular STOP (BEs first, then the FE): + * RESUME takes the BEs out of SUSPENDED and lets them drop their + * suspend_ignored state, STOP then runs the full BE stop sequence. + */ + if (spcm->stream[dir].suspend_ignored) { + spcm->stream[dir].suspend_ignored = false; + + if (free_widget_list && spcm->prepared[substream->stream]) { + struct snd_soc_pcm_runtime *fe = snd_soc_substream_to_rtd(substream); + + ret = dpcm_be_dai_trigger(fe, dir, SNDRV_PCM_TRIGGER_RESUME); + if (!ret) + ret = dpcm_be_dai_trigger(fe, dir, SNDRV_PCM_TRIGGER_STOP); + if (ret < 0) { + spcm_err(spcm, substream->stream, + "failed to stop the BEs of the suspend ignored stream: %d\n", + ret); + err = ret; + } + } + + if (spcm->prepared[substream->stream] && pcm_ops && pcm_ops->trigger) { + ret = pcm_ops->trigger(sdev->component, substream, spcm, + SNDRV_PCM_TRIGGER_STOP, substream->stream); + if (ret < 0) { + spcm_err(spcm, substream->stream, + "failed to stop the suspend ignored stream: %d\n", + ret); + err = ret; + } + } + } + if (spcm->prepared[substream->stream]) { /* stop DMA first if needed */ if (pcm_ops && pcm_ops->platform_stop_during_hw_free)