Skip to contentSkip to conversation

ASoC: soc-compress: Fix deadlock in soc_compr_open_fe

PATCH In review yixuanjiang 3 participants 3 messages Jun 13, 2023 – Jun 15, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: soc-compress: Fix deadlock in soc_compr_open_fe

Modify the error handling flow by release lock. The require pcm_mutex will keep holding if open fail.

Fixes aa9ff6a4955f ("ASoC: soc-compress: Reposition and add pcm_mutex")
Cc [email protected] # v5.15+
---
 sound/soc/soc-compress.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/soc-compress.c +1 -0
index 256e45001f85..b6727b91dd85 100644
@@ -166,6 +166,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
 	snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
 out:
 	dpcm_path_put(&list);
+	mutex_unlock(&fe->card->pcm_mutex);
 be_err:
 	fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
 	mutex_unlock(&fe->card->mutex);
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
maintainer
#1 lore raw

sound/soc/soc-compress.c static int soc_compr_open_fe(struct snd_compr_stream *cstream) · line 170

Quoted 10 lines · yixuanjiang

Modify the error handling flow by release lock. The require pcm_mutex will keep holding if open fail.

+++ b/sound/soc/soc-compress.c

sound/soc/soc-compress.c +1 -0
@@ -166,6 +166,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
 	snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
 out:
 	dpcm_path_put(&list);
+	mutex_unlock(&fe->card->pcm_mutex);
 be_err:

This is really hard to follow due to the lack of any mutex_lock()s in the function, I think because this is intended to undo snd_soc_dpcm_mutex_lock(fe) but if that's the case why is it not using snd_soc_dpcm_mutex_unlock(fe) like the success path does? Given the use of classes not doing that looks like it'll create lockdep issues.

I'd expect the unlock to match the lock.

#2 lore raw
Quoted 18 lines · Mark Brown

sound/soc/soc-compress.c static int soc_compr_open_fe(struct snd_compr_stream *cstream) · line 170

Quoted 10 lines · yixuanjiang

Modify the error handling flow by release lock. The require pcm_mutex will keep holding if open fail.

+++ b/sound/soc/soc-compress.c

sound/soc/soc-compress.c +1 -0
@@ -166,6 +166,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
 	snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
 out:
 	dpcm_path_put(&list);
+	mutex_unlock(&fe->card->pcm_mutex);
 be_err:

This is really hard to follow due to the lack of any mutex_lock()s in the function, I think because this is intended to undo snd_soc_dpcm_mutex_lock(fe) but if that's the case why is it not using snd_soc_dpcm_mutex_unlock(fe) like the success path does? Given the use of classes not doing that looks like it'll create lockdep issues.

Quoted 1 line

I'd expect the unlock to match the lock.

Yes, and judging from the context of the patch I believe this was based off of stable 5.15.y tree. The locking has been refactored since. So Yixuan, please rebase/adjust your patch on top of Linus's mainline tree and resend. Thanks!

--
Carlos Llamas