All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suyuan Wang" <shyckless@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link
Date: Thu, 19 Nov 2026 19:44:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-223965@kernel.org> (raw)
In-Reply-To: <20261119-asoc-dpcm-pause-link-v1-1-5b97347b5771@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: soc-pcm: duplicate PAUSE_PUSH sent on STOP in
  dpcm_be_dai_trigger()
- [Medium] ASoC: soc-pcm: stale pause count after prepare/hw_free in
  dpcm_be_dai_trigger()
- [Medium] ASoC: soc-pcm: BE left in PAUSED state on close in
  dpcm_be_dai_stop()
--

commit 30a052e7da7505ef9d19e12059b179dfd9931fe2
Author: Suyuan Wang <stevewong@hust.edu.cn>

ASoC: soc-pcm: Track BE pause per FE-BE link

This commit replaces the per-FE fe_pause boolean with a per-link paused
flag in struct snd_soc_dpcm so that BE pause refcounting and trigger rollbacks
are tracked per FE-BE link.

> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> index ef8ccf52798eb..cb8d23756b1e0 100644
> --- a/sound/soc/soc-pcm.c
> +++ b/sound/soc/soc-pcm.c
> @@ -1685,6 +1685,17 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
>  		if (!snd_soc_dpcm_can_be_update(fe, be, stream))
>  			continue;
>  
> +		/*
> +		 * A pause may survive until close, e.g. after system suspend.
> +		 * Drop the pause this link still holds.
> +		 */
> +		if (dpcm->paused) {
> +			snd_pcm_stream_lock_irq(be_substream);
> +			dpcm->paused = false;
> +			be->dpcm[stream].be_pause--;
> +			snd_pcm_stream_unlock_irq(be_substream);
> +		}
> +
>  		if (be->dpcm[stream].users == 0) {
>  			dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
>  				snd_pcm_direction_name(stream),

[Severity: Medium]
Can this leave the BE stuck in SND_SOC_DPCM_STATE_PAUSED when another idle FE
still has the shared BE open?

If FE1 is paused on a shared BE across system suspend and then closed while
FE2 is still open (be->dpcm[stream].users > 1), dpcm_be_dai_stop() drops
be->dpcm[stream].be_pause to 0 and returns early after decrementing users.
That leaves be->dpcm[stream].state at SND_SOC_DPCM_STATE_PAUSED with
be_start == 0 and be_pause == 0, causing later dpcm_be_dai_hw_params() calls
for FE2 to skip the BE because its state is not OPEN, HW_PARAMS, or HW_FREE.

> @@ -2220,7 +2231,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
>  			       int cmd)
>  {
>  	struct snd_soc_pcm_runtime *be;
> -	bool pause_stop_transition;
> +	bool was_paused;
>  	struct snd_soc_dpcm *dpcm;
>  	unsigned long flags;
>  	int ret = 0;
> @@ -2248,6 +2259,16 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
>  			    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
>  				goto next;
>  
> +			/*
> +			 * A stream suspended while paused and prepared again
> +			 * starts without a PAUSE_RELEASE: drop its pause here.
> +			 */
> +			was_paused = dpcm->paused;
> +			if (was_paused) {
> +				dpcm->paused = false;
> +				be->dpcm[stream].be_pause--;
> +			}
> +
>  			be->dpcm[stream].be_start++;
>  			if (be->dpcm[stream].be_start != 1)
>  				goto next;
> @@ -2260,6 +2281,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
>  						      SNDRV_PCM_TRIGGER_START);
>  			if (ret) {
>  				be->dpcm[stream].be_start--;
> +				if (was_paused) {
> +					dpcm->paused = true;
> +					be->dpcm[stream].be_pause++;
> +				}
>  				goto next;
>  			}

[Severity: Medium]
Does deferring pause cleanup until SNDRV_PCM_TRIGGER_START leave a stale
be->dpcm[stream].be_pause count after a suspended stream is prepared or
hw_freed?

When a paused FE is suspended and then recovered with snd_pcm_prepare() or
snd_pcm_drop() + snd_pcm_hw_free(), the FE transitions to PREPARE or HW_FREE
without sending PAUSE_RELEASE or STOP.  Until that FE either starts or closes,
dpcm->paused remains true and be->dpcm[stream].be_pause stays elevated (and is
restored if SNDRV_PCM_TRIGGER_START fails).  If another FE sharing the BE
starts and stops in the meantime, its STOP sees be_pause != 0 and sends
SNDRV_PCM_TRIGGER_PAUSE_PUSH instead of SNDRV_PCM_TRIGGER_STOP, leaving the BE
in SND_SOC_DPCM_STATE_PAUSED when no stream is paused.

[ ... ]

> @@ -2307,30 +2338,32 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
>  			    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
>  				goto next;
>  
> -			if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
> +			/*
> +			 * A paused FE left be_start when it paused and only
> +			 * holds a pause on this BE.
> +			 */
> +			was_paused = dpcm->paused;
> +			if (was_paused) {
> +				dpcm->paused = false;
> +				be->dpcm[stream].be_pause--;
> +			} else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
>  				be->dpcm[stream].be_start--;
> +			}
>  
>  			if (be->dpcm[stream].be_start != 0)
>  				goto next;
>  
> -			pause_stop_transition = false;
> -			if (fe->dpcm[stream].fe_pause) {
> -				pause_stop_transition = true;
> -				fe->dpcm[stream].fe_pause = false;
> -				be->dpcm[stream].be_pause--;
> -			}
> -
>  			if (be->dpcm[stream].be_pause != 0)
>  				ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
>  			else
>  				ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_STOP);

[Severity: Medium]
Can SNDRV_PCM_TRIGGER_STOP send a duplicate SNDRV_PCM_TRIGGER_PAUSE_PUSH to a
BE that is already in SND_SOC_DPCM_STATE_PAUSED?

When be->dpcm[stream].state is already SND_SOC_DPCM_STATE_PAUSED,
be->dpcm[stream].be_start is 0.  If two paused FEs share the BE (be_pause == 2)
and one of them is stopped, be_pause drops to 1 and execution falls through to
soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH) on the
already-paused BE.  The same duplicate PAUSE_PUSH happens if STOP runs for an
unpaused FE (was_paused == false) while another FE holds the BE in
SND_SOC_DPCM_STATE_PAUSED, such as when snd_pcm_undo_start() sends STOP after a
failed start.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-asoc-dpcm-pause-link-v1-1-5b97347b5771@gmail.com?part=1

  reply	other threads:[~2026-11-19 19:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:22 [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link Suyuan Wang
2026-11-19 19:22 ` Suyuan Wang via B4 Relay
2026-11-19 19:44 ` sashiko-bot [this message]
2026-11-19 19:50   ` Wong Steve

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-223965@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shyckless@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.