From 9cfc1926ef8c8e8db81558cbc6ba0cb73c2d1f5b Mon Sep 17 00:00:00 2001 From: Deru Wang Date: Tue, 24 Mar 2020 20:06:55 +0800 Subject: [PATCH] asoc: fix kernel panic due to Non-NULL ac set pcm->audio_client NULL when open pcm failed and add NULL pointer check. Change-Id: I5a293e09449d3b616761bbd66326274849ce2f58 Signed-off-by: Deru Wang --- asoc/msm-pcm-loopback-v2.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/asoc/msm-pcm-loopback-v2.c b/asoc/msm-pcm-loopback-v2.c index a741b46cf4d8..c0e567a7c262 100644 --- a/asoc/msm-pcm-loopback-v2.c +++ b/asoc/msm-pcm-loopback-v2.c @@ -307,6 +307,7 @@ static int msm_pcm_open(struct snd_pcm_substream *substream) dev_err(component->dev, "%s: pcm out open failed\n", __func__); q6asm_audio_client_free(pcm->audio_client); + pcm->audio_client = NULL; mutex_unlock(&pcm->lock); return -ENOMEM; } @@ -346,8 +347,10 @@ static void stop_pcm(struct msm_pcm_loopback *pcm) struct snd_soc_pcm_runtime *soc_pcm_rx; struct snd_soc_pcm_runtime *soc_pcm_tx; - if (pcm->audio_client == NULL) + if (pcm->audio_client == NULL) { + pr_err("%s: audio client freed\n", __func__); return; + } mutex_lock(&loopback_session_lock); q6asm_cmd(pcm->audio_client, CMD_CLOSE); @@ -445,6 +448,12 @@ static int msm_pcm_prepare(struct snd_pcm_substream *substream) dev_dbg(component->dev, "%s: ASM loopback stream:%d\n", __func__, substream->stream); + if (!pcm || !pcm->audio_client) { + mutex_unlock(&pcm->lock); + pr_err("%s: private data null or audio client freed\n", __func__); + return -EINVAL; + } + if (pcm->playback_start && pcm->capture_start) { mutex_unlock(&pcm->lock); return ret;