From 2b0c995899a8967e90596e11dfbe1dc0b91ce047 Mon Sep 17 00:00:00 2001 From: Vikram Panduranga Date: Mon, 14 Oct 2019 12:44:25 -0700 Subject: [PATCH] asoc: msm-pcm: move null ptr check after lock Null pointer for runtime is checked before acquiring the lock. By the time, it acquires lock and tries to access private data runtime may be removed which can lead to null ptr dereference. Change-Id: I86ca89bd7dbd765c040bab2a292f62c2d3164140 Signed-off-by: Vikram Panduranga --- asoc/msm-pcm-q6-v2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asoc/msm-pcm-q6-v2.c b/asoc/msm-pcm-q6-v2.c index 5626d49b4648..60e84cb7dd2d 100644 --- a/asoc/msm-pcm-q6-v2.c +++ b/asoc/msm-pcm-q6-v2.c @@ -1797,11 +1797,11 @@ static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol, } } - if (!substream->runtime || !rtd) + if (!rtd) return 0; mutex_lock(&pdata->lock); - prtd = substream->runtime->private_data; + prtd = substream->runtime ? substream->runtime->private_data : NULL; if (prtd) { prtd->set_channel_map = true; for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++) @@ -1864,11 +1864,11 @@ static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol, memset(ucontrol->value.integer.value, 0, sizeof(ucontrol->value.integer.value)); - if (!substream->runtime || !rtd) + if (!rtd) return 0; /* no channels set */ mutex_lock(&pdata->lock); - prtd = substream->runtime->private_data; + prtd = substream->runtime ? substream->runtime->private_data : NULL; if (prtd && prtd->set_channel_map == true) { for (i = 0; i < PCM_FORMAT_MAX_NUM_CHANNEL_V8; i++)