diff mbox series

ASoC: soc-compress: Reposition and add pcm_mutex

Message ID 626742236.41670226602525.JavaMail.epsvc@epcpadp3 (mailing list archive)
State Superseded
Headers show
Series ASoC: soc-compress: Reposition and add pcm_mutex | expand

Commit Message

강신형 Dec. 5, 2022, 7:46 a.m. UTC
From a385cc2614c17ba3002b263c0ca47dfbf6395c78 Mon Sep 17 00:00:00 2001
From: "s47.kang" <s47.kang@samsung.com>
Date: Fri, 2 Dec 2022 15:45:16 +0900
Subject: [PATCH] ASoC: soc-compress.c: Reposition and add pcm_mutex.

If panic_on_warn is set and compress stream(DPCM) is started,
then kernel panic will occurs because card->pcm_mutex isn't held
appropriately in
soc_compr_set_params_fe, soc_compr_open_fe and soc_compr_free_fe.
So, I reposition and add pcm_mutex to resolve lockdep error.

Signed-off-by: Shinhyung Kang <s47.kang@samsung.com>
---
 sound/soc/soc-compress.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

 	fe->dpcm[stream].runtime = fe_substream->runtime;
@@ -184,7 +186,6 @@ static int soc_compr_open_fe(struct snd_compr_stream
*cstream)
 	fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
 	fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
 
-	mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
 	snd_soc_runtime_activate(fe, stream);
 	mutex_unlock(&fe->card->pcm_mutex);
 
@@ -215,7 +216,6 @@ static int soc_compr_free_fe(struct snd_compr_stream
*cstream)
 
 	mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
 	snd_soc_runtime_deactivate(fe, stream);
-	mutex_unlock(&fe->card->pcm_mutex);
 
 	fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
 
@@ -234,6 +234,8 @@ static int soc_compr_free_fe(struct snd_compr_stream
*cstream)
 
 	dpcm_be_disconnect(fe, stream);
 
+	mutex_unlock(&fe->card->pcm_mutex);
+
 	fe->dpcm[stream].runtime = NULL;
 
 	snd_soc_link_compr_shutdown(cstream, 0);
@@ -409,8 +411,9 @@ static int soc_compr_set_params_fe(struct
snd_compr_stream *cstream,
 	ret = snd_soc_link_compr_set_params(cstream);
 	if (ret < 0)
 		goto out;
-
+	mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
 	dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
+	mutex_unlock(&fe->card->pcm_mutex);
 	fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
 
 out:

Comments

Krzysztof Kozlowski Dec. 5, 2022, 9:48 a.m. UTC | #1
On 05/12/2022 08:46, 강신형 wrote:
> From a385cc2614c17ba3002b263c0ca47dfbf6395c78 Mon Sep 17 00:00:00 2001
> From: "s47.kang" <s47.kang@samsung.com>
> Date: Fri, 2 Dec 2022 15:45:16 +0900
> Subject: [PATCH] ASoC: soc-compress.c: Reposition and add pcm_mutex.

This does not match your subject... and having subject twice is also
confusing. Please fix your mailer.

Additionally, this is like third patch, right? So please mark it as v3
(git format-patch helps in this).

> 
> If panic_on_warn is set and compress stream(DPCM) is started,
> then kernel panic will occurs because card->pcm_mutex isn't held
> appropriately in

So the problem is panic_on_warn or wrong synchronization? It's the
second, so skip unrelated information and instead describe the real
problem, e.g. what exactly lockdep reported.

> soc_compr_set_params_fe, soc_compr_open_fe and soc_compr_free_fe.
> So, I reposition and add pcm_mutex to resolve lockdep error.
> 
> Signed-off-by: Shinhyung Kang <s47.kang@samsung.com>
> ---
>  sound/soc/soc-compress.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 870f13e1d389..7bce5088b455 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -149,6 +149,8 @@  static int soc_compr_open_fe(struct snd_compr_stream
*cstream)
 	if (ret < 0)
 		goto be_err;
 
+	mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
+
 	/* calculate valid and active FE <-> BE dpcms */
 	dpcm_process_paths(fe, stream, &list, 1);