asoc: Add check for substream ref_count before access the substream.

Add check for substream ref count before access the substream.

Change-Id: Iccb6226519e8fddf624f82160a0d8d22641944db
Signed-off-by: Prasad Kumpatla <nkumpat@codeaurora.org>
This commit is contained in:
Prasad Kumpatla
2020-06-25 19:38:34 +05:30
committed by Gerrit - the friendly Code Review server
parent 5d06056f5b
commit ef02f940ae
3 changed files with 80 additions and 35 deletions

View File

@@ -552,13 +552,15 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
goto exit; goto exit;
} }
mutex_lock(&loopback_session_lock); mutex_lock(&loopback_session_lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (!prtd) { prtd = substream->runtime->private_data;
rc = -ENODEV; if (!prtd) {
mutex_unlock(&loopback_session_lock); rc = -ENODEV;
goto exit; mutex_unlock(&loopback_session_lock);
goto exit;
}
rc = pcm_loopback_set_volume(prtd, volume);
} }
rc = pcm_loopback_set_volume(prtd, volume);
mutex_unlock(&loopback_session_lock); mutex_unlock(&loopback_session_lock);
exit: exit:
return rc; return rc;
@@ -584,13 +586,15 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
goto exit; goto exit;
} }
mutex_lock(&loopback_session_lock); mutex_lock(&loopback_session_lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (!prtd) { prtd = substream->runtime->private_data;
rc = -ENODEV; if (!prtd) {
mutex_unlock(&loopback_session_lock); rc = -ENODEV;
goto exit; mutex_unlock(&loopback_session_lock);
goto exit;
}
ucontrol->value.integer.value[0] = prtd->volume;
} }
ucontrol->value.integer.value[0] = prtd->volume;
mutex_unlock(&loopback_session_lock); mutex_unlock(&loopback_session_lock);
exit: exit:
return rc; return rc;
@@ -888,6 +892,12 @@ static int msm_pcm_channel_mixer_cfg_ctl_put(struct snd_kcontrol *kcontrol,
chmixer_pspd); chmixer_pspd);
mutex_lock(&loopback_session_lock); mutex_lock(&loopback_session_lock);
if (substream->ref_count <= 0) {
pr_err_ratelimited("%s: substream ref_count:%d invalid\n",
__func__, substream->ref_count);
mutex_unlock(&loopback_session_lock);
return -EINVAL;
}
if (chmixer_pspd->enable && substream->runtime) { if (chmixer_pspd->enable && substream->runtime) {
prtd = substream->runtime->private_data; prtd = substream->runtime->private_data;
if (!prtd) { if (!prtd) {

View File

@@ -762,9 +762,11 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
return -ENODEV; return -ENODEV;
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) prtd = substream->runtime->private_data;
ucontrol->value.integer.value[0] = prtd->volume; if (prtd)
ucontrol->value.integer.value[0] = prtd->volume;
}
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return 0; return 0;
} }
@@ -807,10 +809,12 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) { prtd = substream->runtime->private_data;
rc = msm_pcm_set_volume(prtd, volume); if (prtd) {
prtd->volume = volume; rc = msm_pcm_set_volume(prtd, volume);
prtd->volume = volume;
}
} }
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return rc; return rc;

View File

@@ -1330,7 +1330,12 @@ static int msm_pcm_adsp_stream_cmd_put(struct snd_kcontrol *kcontrol,
ret = -EINVAL; ret = -EINVAL;
goto done; goto done;
} }
if (substream->ref_count <= 0) {
pr_err_ratelimited("%s substream ref_count:%d invalid\n",
__func__, substream->ref_count);
ret = -EINVAL;
goto done;
}
prtd = substream->runtime->private_data; prtd = substream->runtime->private_data;
if (prtd == NULL) { if (prtd == NULL) {
pr_err("%s prtd is null.\n", __func__); pr_err("%s prtd is null.\n", __func__);
@@ -1561,9 +1566,11 @@ static int msm_pcm_volume_ctl_get(struct snd_kcontrol *kcontrol,
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) prtd = substream->runtime->private_data;
ucontrol->value.integer.value[0] = prtd->volume; if (prtd)
ucontrol->value.integer.value[0] = prtd->volume;
}
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return 0; return 0;
} }
@@ -1607,10 +1614,12 @@ static int msm_pcm_volume_ctl_put(struct snd_kcontrol *kcontrol,
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) { prtd = substream->runtime->private_data;
rc = msm_pcm_set_volume(prtd, volume); if (prtd) {
prtd->volume = volume; rc = msm_pcm_set_volume(prtd, volume);
prtd->volume = volume;
}
} }
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return rc; return rc;
@@ -1678,9 +1687,11 @@ static int msm_pcm_compress_ctl_get(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) prtd = substream->runtime->private_data;
ucontrol->value.integer.value[0] = prtd->compress_enable; if (prtd)
ucontrol->value.integer.value[0] = prtd->compress_enable;
}
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return 0; return 0;
} }
@@ -1710,11 +1721,13 @@ static int msm_pcm_compress_ctl_put(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
prtd = substream->runtime->private_data; if (substream->ref_count > 0) {
if (prtd) { prtd = substream->runtime->private_data;
pr_debug("%s: setting compress flag to 0x%x\n", if (prtd) {
__func__, compress); pr_debug("%s: setting compress flag to 0x%x\n",
prtd->compress_enable = compress; __func__, compress);
prtd->compress_enable = compress;
}
} }
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return rc; return rc;
@@ -1824,6 +1837,12 @@ static int msm_pcm_chmap_ctl_put(struct snd_kcontrol *kcontrol,
return 0; return 0;
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
if (substream->ref_count <= 0) {
pr_err_ratelimited("%s: substream ref_count:%d invalid\n",
__func__, substream->ref_count);
mutex_unlock(&pdata->lock);
return -EINVAL;
}
prtd = substream->runtime ? substream->runtime->private_data : NULL; prtd = substream->runtime ? substream->runtime->private_data : NULL;
if (prtd) { if (prtd) {
prtd->set_channel_map = true; prtd->set_channel_map = true;
@@ -1891,6 +1910,12 @@ static int msm_pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol,
return 0; /* no channels set */ return 0; /* no channels set */
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
if (substream->ref_count <= 0) {
pr_err_ratelimited("%s: substream ref_count:%d invalid\n",
__func__, substream->ref_count);
mutex_unlock(&pdata->lock);
return -EINVAL;
}
prtd = substream->runtime ? substream->runtime->private_data : NULL; prtd = substream->runtime ? substream->runtime->private_data : NULL;
if (prtd && prtd->set_channel_map == true) { if (prtd && prtd->set_channel_map == true) {
@@ -2180,6 +2205,12 @@ static int msm_pcm_channel_mixer_cfg_ctl_put(struct snd_kcontrol *kcontrol,
} }
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
if (substream->ref_count <= 0) {
pr_err_ratelimited("%s: substream ref_count:%d invalid\n",
__func__, substream->ref_count);
mutex_unlock(&pdata->lock);
return -EINVAL;
}
prtd = substream->runtime ? substream->runtime->private_data : NULL; prtd = substream->runtime ? substream->runtime->private_data : NULL;
if (chmixer_pspd->enable && prtd) { if (chmixer_pspd->enable && prtd) {
if (session_type == SESSION_TYPE_RX && if (session_type == SESSION_TYPE_RX &&