diff mbox series

Subject: [PATCH v2] ASoC: soc-pcm: fix BE dai not hw_free and shutdown during mixer update

Message ID ALMAWwB5CP9aAcKXCU5FzqqF.1.1590747164172.Hmail.zhucancan@vivo.com (mailing list archive)
State New, archived
Headers show
Series Subject: [PATCH v2] ASoC: soc-pcm: fix BE dai not hw_free and shutdown during mixer update | expand

Commit Message

朱灿灿 May 29, 2020, 10:12 a.m. UTC
FE state is SND_SOC_DPCM_STATE_PREPARE now, BE1 is
used by FE.

Later when new BE2 is added to FE by mixer update,
it will call dpcm_run_update_startup() to update
BE2's state, but unfortunately BE2 .prepare() meets
error, it will disconnect all non started BE.

This make BE1 dai skip .hw_free() and .shutdown(),
and the BE1 users will never decrease to zero.

Signed-off-by: zhucancan <zhucancan@vivo.com>
---
re-format patch content v2
---
 sound/soc/soc-pcm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Pierre-Louis Bossart June 2, 2020, 4:19 p.m. UTC | #1
On 5/29/20 5:12 AM, 朱灿灿 wrote:
> FE state is SND_SOC_DPCM_STATE_PREPARE now, BE1 is
> used by FE.
> 
> Later when new BE2 is added to FE by mixer update,
> it will call dpcm_run_update_startup() to update
> BE2's state, but unfortunately BE2 .prepare() meets
> error, it will disconnect all non started BE.
> 
> This make BE1 dai skip .hw_free() and .shutdown(),
> and the BE1 users will never decrease to zero.
> 
> Signed-off-by: zhucancan <zhucancan@vivo.com>
> ---
> re-format patch content v2
> ---
>   sound/soc/soc-pcm.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> index 1f302de44052..df34422bd0dd 100644
> --- a/sound/soc/soc-pcm.c
> +++ b/sound/soc/soc-pcm.c
> @@ -2730,12 +2730,12 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
>   close:
>   	dpcm_be_dai_shutdown(fe, stream);
>   disconnect:
> -	/* disconnect any non started BEs */
> +	/* disconnect any closed BEs */
>   	spin_lock_irqsave(&fe->card->dpcm_lock, flags);
>   	for_each_dpcm_be(fe, stream, dpcm) {
>   		struct snd_soc_pcm_runtime *be = dpcm->be;
> -		if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
> -				dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
> +		if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
> +			dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
>   	}
>   	spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);

This change is quite hard to review, this error handling can be called 
from multiple places.

I *think* it's correct because in all cases where the 
disconnect/close/hw_free labels are reached, the non-shared BEs either 
remain or are put in the DPCM_STATE_CLOSE state before doing this test.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

It really wouldn't hurt though if others double-checked this change...
diff mbox series

Patch

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 1f302de44052..df34422bd0dd 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2730,12 +2730,12 @@  static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
 close:
 	dpcm_be_dai_shutdown(fe, stream);
 disconnect:
-	/* disconnect any non started BEs */
+	/* disconnect any closed BEs */
 	spin_lock_irqsave(&fe->card->dpcm_lock, flags);
 	for_each_dpcm_be(fe, stream, dpcm) {
 		struct snd_soc_pcm_runtime *be = dpcm->be;
-		if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
-				dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
+		if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
+			dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
 	}
 	spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);