Browse Source

asoc: add NULL check before access pointer

Add NULL check before access pointer to avoid dereference.

Change-Id: I2c7408348a0acf1a3801a5869f62bae328858beb
Signed-off-by: Meng Wang <[email protected]>
Meng Wang 6 years ago
parent
commit
8a2a104156
2 changed files with 37 additions and 8 deletions
  1. 21 8
      asoc/msm-compress-q6-v2.c
  2. 16 0
      asoc/msm-transcode-loopback-q6-v2.c

+ 21 - 8
asoc/msm-compress-q6-v2.c

@@ -363,12 +363,17 @@ static int msm_compr_set_volume(struct snd_compr_stream *cstream,
 	}
 	rtd = cstream->private_data;
 	prtd = cstream->runtime->private_data;
-	component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
 
-	if (!rtd || !component || !prtd || !prtd->audio_client) {
+	if (!rtd || !prtd || !prtd->audio_client) {
 		pr_err("%s: invalid rtd, prtd or audio client", __func__);
 		return rc;
 	}
+	component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
+	if (!component) {
+		pr_err("%s: invalid component\n", __func__);
+		return rc;
+	}
+
 	pdata = snd_soc_component_get_drvdata(component);
 
 	if (prtd->compr_passthr != LEGACY_PCM) {
@@ -1810,12 +1815,16 @@ static int msm_compr_playback_free(struct snd_compr_stream *cstream)
 	}
 	runtime = cstream->runtime;
 	soc_prtd = cstream->private_data;
-	component = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
-	if (!runtime || !soc_prtd || !component) {
-		pr_err("%s runtime or soc_prtd or component is null\n",
+	if (!runtime || !soc_prtd) {
+		pr_err("%s runtime or soc_prtd is null\n",
 			__func__);
 		return 0;
 	}
+	component = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
+	if (!component) {
+		pr_err("%s component is null\n", __func__);
+		return 0;
+	}
 	prtd = runtime->private_data;
 	if (!prtd) {
 		pr_err("%s prtd is null\n", __func__);
@@ -1913,12 +1922,16 @@ static int msm_compr_capture_free(struct snd_compr_stream *cstream)
 	}
 	runtime = cstream->runtime;
 	soc_prtd = cstream->private_data;
+	if (!runtime || !soc_prtd) {
+		pr_err("%s runtime or soc_prtd is null\n", __func__);
+		return 0;
+	}
 	component = snd_soc_rtdcom_lookup(soc_prtd, DRV_NAME);
-	if (!runtime || !soc_prtd || !component) {
-		pr_err("%s runtime or soc_prtd or component is null\n",
-			__func__);
+	if (!component) {
+		pr_err("%s component is null\n", __func__);
 		return 0;
 	}
+
 	prtd = runtime->private_data;
 	if (!prtd) {
 		pr_err("%s prtd is null\n", __func__);

+ 16 - 0
asoc/msm-transcode-loopback-q6-v2.c

@@ -435,7 +435,15 @@ static int msm_transcode_loopback_set_params(struct snd_compr_stream *cstream,
 	mutex_lock(&trans->lock);
 
 	rtd = snd_pcm_substream_chip(cstream);
+	if (!rtd) {
+		pr_err("%s: rtd is NULL\n", __func__);
+		return -EINVAL;
+	}
 	component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
+	if (!component) {
+		pr_err("%s: component is NULL\n", __func__);
+		return -EINVAL;
+	}
 	pdata = snd_soc_component_get_drvdata(component);
 
 	if (cstream->direction == SND_COMPRESS_PLAYBACK) {
@@ -606,7 +614,15 @@ static int msm_transcode_loopback_set_metadata(struct snd_compr_stream *cstream,
 	}
 
 	rtd = snd_pcm_substream_chip(cstream);
+	if (!rtd) {
+		pr_err("%s: rtd is NULL\n", __func__);
+		return -EINVAL;
+	}
 	component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
+	if (!component) {
+		pr_err("%s: component is NULL\n", __func__);
+		return -EINVAL;
+	}
 	pdata = snd_soc_component_get_drvdata(component);
 
 	prtd = cstream->runtime->private_data;