diff options
| author | xsang <xsang@codeaurora.org> | 2020-09-03 23:49:59 +0800 |
|---|---|---|
| committer | xsang <xsang@codeaurora.org> | 2020-09-03 23:54:45 +0800 |
| commit | a844e7d2b4f9583aa09e9af5d58ff084831cb509 (patch) | |
| tree | aa558fbe54c5d45e15e84b6efc45023d24b6bba7 | |
| parent | 5948b13320d83080a008e21514bbe6e61d39871a (diff) | |
asoc: add missing null check for pcm pointer of snd_pcm_volume
In platform driver volume controls, add null check for
pcm pointer of struct snd_pcm_volume.
Change-Id: Icc139ae7dde0d45a3101b185ac69381df9e5e6c5
Signed-off-by: xsang <xsang@codeaurora.org>
| -rw-r--r-- | sound/soc/msm/qdsp6v2/msm-pcm-loopback-v2.c | 29 | ||||
| -rw-r--r-- | sound/soc/msm/qdsp6v2/msm-pcm-q6-noirq.c | 32 | ||||
| -rw-r--r-- | sound/soc/msm/qdsp6v2/msm-pcm-q6-v2.c | 30 |
3 files changed, 79 insertions, 12 deletions
diff --git a/sound/soc/msm/qdsp6v2/msm-pcm-loopback-v2.c b/sound/soc/msm/qdsp6v2/msm-pcm-loopback-v2.c index 0add46fb979f..24f9740a9511 100644 --- a/sound/soc/msm/qdsp6v2/msm-pcm-loopback-v2.c +++ b/sound/soc/msm/qdsp6v2/msm-pcm-loopback-v2.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. +/* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -545,11 +545,23 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, { int rc = 0; struct snd_pcm_volume *vol = kcontrol->private_data; - struct snd_pcm_substream *substream = vol->pcm->streams[0].substream; + struct snd_pcm_substream *substream = NULL; struct msm_pcm_loopback *prtd; int volume = ucontrol->value.integer.value[0]; pr_debug("%s: volume : 0x%x\n", __func__, volume); + + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + + substream = vol->pcm->streams[0].substream; mutex_lock(&loopback_session_lock); if ((!substream) || (!substream->runtime)) { pr_err("%s substream or runtime not found\n", __func__); @@ -579,6 +591,19 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, struct msm_pcm_loopback *prtd; pr_debug("%s\n", __func__); + + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + + substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + if ((!substream) || (!substream->runtime)) { pr_err("%s substream or runtime not found\n", __func__); rc = -ENODEV; diff --git a/sound/soc/msm/qdsp6v2/msm-pcm-q6-noirq.c b/sound/soc/msm/qdsp6v2/msm-pcm-q6-noirq.c index 5c78349f8d70..4ef4ae7d72c8 100644 --- a/sound/soc/msm/qdsp6v2/msm-pcm-q6-noirq.c +++ b/sound/soc/msm/qdsp6v2/msm-pcm-q6-noirq.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2016-2017, 2019 The Linux Foundation. All rights reserved. +/* Copyright (c) 2016-2017, 2019-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -662,12 +662,22 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, { struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct msm_plat_data *pdata = NULL; - struct snd_pcm_substream *substream = - vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_pcm_substream *substream = NULL; struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; pr_debug("%s\n", __func__); + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + + substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; if (!substream) { pr_err("%s substream not found\n", __func__); return -ENODEV; @@ -699,13 +709,25 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, int rc = 0; struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct msm_plat_data *pdata = NULL; - struct snd_pcm_substream *substream = - vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_pcm_substream *substream = NULL; struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; int volume = ucontrol->value.integer.value[0]; pr_debug("%s: volume : 0x%x\n", __func__, volume); + + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + + substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + if (!substream) { pr_err("%s substream not found\n", __func__); return -ENODEV; diff --git a/sound/soc/msm/qdsp6v2/msm-pcm-q6-v2.c b/sound/soc/msm/qdsp6v2/msm-pcm-q6-v2.c index b2154620c8ae..c1ef60bd8cba 100644 --- a/sound/soc/msm/qdsp6v2/msm-pcm-q6-v2.c +++ b/sound/soc/msm/qdsp6v2/msm-pcm-q6-v2.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -1389,12 +1389,22 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol, { struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); struct msm_plat_data *pdata = NULL; - struct snd_pcm_substream *substream = - vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_pcm_substream *substream = NULL; struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_audio *prtd; pr_debug("%s\n", __func__); + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + if (!substream) { pr_err("%s substream not found\n", __func__); return -ENODEV; @@ -1426,14 +1436,24 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol, { int rc = 0; struct snd_pcm_volume *vol = snd_kcontrol_chip(kcontrol); - struct snd_pcm_substream *substream = - vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + struct snd_pcm_substream *substream = NULL; struct msm_audio *prtd; int volume = ucontrol->value.integer.value[0]; struct snd_soc_pcm_runtime *soc_prtd = NULL; struct msm_plat_data *pdata = NULL; pr_debug("%s: volume : 0x%x\n", __func__, volume); + if (!vol) { + pr_err("%s: vol is NULL\n", __func__); + return -ENODEV; + } + + if (!vol->pcm) { + pr_err("%s: vol->pcm is NULL\n", __func__); + return -ENODEV; + } + + substream = vol->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; if (!substream) { pr_err("%s: substream not found\n", __func__); return -ENODEV; |
