Browse Source

Merge "asoc: lsm: free confidence_levels memory to avoid memory leakage"

qctecmdr 5 years ago
parent
commit
c5598a866d
1 changed files with 12 additions and 9 deletions
  1. 12 9
      asoc/msm-lsm-client.c

+ 12 - 9
asoc/msm-lsm-client.c

@@ -659,6 +659,10 @@ static int msm_lsm_set_conf(struct snd_pcm_substream *substream,
 			"%s: Failed to set min_conf_levels, err = %d\n",
 			__func__, rc);
 
+	if (prtd->lsm_client->confidence_levels) {
+		kfree(prtd->lsm_client->confidence_levels);
+		prtd->lsm_client->confidence_levels = NULL;
+	}
 	return rc;
 }
 
@@ -1055,7 +1059,6 @@ static int msm_lsm_ioctl_shared(struct snd_pcm_substream *substream,
 	struct snd_pcm_runtime *runtime;
 	struct lsm_priv *prtd;
 	struct snd_lsm_detection_params det_params;
-	uint8_t *confidence_level = NULL;
 	uint32_t max_detection_stages_supported = LSM_MAX_STAGES_PER_SESSION;
 
 	if (!substream || !substream->private_data) {
@@ -1210,12 +1213,12 @@ static int msm_lsm_ioctl_shared(struct snd_pcm_substream *substream,
 			dev_err(rtd->dev,
 				"%s: Register snd Model v2 failed =%d\n",
 			       __func__, rc);
-			kfree(confidence_level);
 			q6lsm_snd_model_buf_free(prtd->lsm_client, &p_info);
 		}
-
-		kfree(prtd->lsm_client->confidence_levels);
-		prtd->lsm_client->confidence_levels = NULL;
+		if (prtd->lsm_client->confidence_levels) {
+			kfree(prtd->lsm_client->confidence_levels);
+			prtd->lsm_client->confidence_levels = NULL;
+		}
 		break;
 	}
 	case SNDRV_LSM_SET_PARAMS:
@@ -1247,10 +1250,10 @@ static int msm_lsm_ioctl_shared(struct snd_pcm_substream *substream,
 			dev_err(rtd->dev,
 				"%s: Failed to set params, err = %d\n",
 				__func__, rc);
-
-		kfree(prtd->lsm_client->confidence_levels);
-		prtd->lsm_client->confidence_levels = NULL;
-
+		if (prtd->lsm_client->confidence_levels) {
+			kfree(prtd->lsm_client->confidence_levels);
+			prtd->lsm_client->confidence_levels = NULL;
+		}
 		break;
 
 	case SNDRV_LSM_DEREG_SND_MODEL: