Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4746e99 authored by Xiaoyu Ye's avatar Xiaoyu Ye
Browse files

ASoC: sdm845: Add check before dereferencing pointer



Add check for pinctrl structure pointer before
dereferencing to avoid invalid memory access.

Change-Id: Ia70b2e0fa7fdfbf7c4dc5371ed51438aa0eeb319
Signed-off-by: default avatarXiaoyu Ye <benyxy@codeaurora.org>
parent 684a7b03
Loading
Loading
Loading
Loading
+15 −8
Original line number Original line Diff line number Diff line
@@ -3934,6 +3934,13 @@ static int msm_set_pinctrl(struct msm_pinctrl_info *pinctrl_info,
		ret = -EINVAL;
		ret = -EINVAL;
		goto err;
		goto err;
	}
	}

	if (pinctrl_info->pinctrl == NULL) {
		pr_err("%s: pinctrl_info->pinctrl is NULL\n", __func__);
		ret = -EINVAL;
		goto err;
	}

	curr_state = pinctrl_info->curr_state;
	curr_state = pinctrl_info->curr_state;
	pinctrl_info->curr_state = new_state;
	pinctrl_info->curr_state = new_state;
	pr_debug("%s: curr_state = %s new_state = %s\n", __func__,
	pr_debug("%s: curr_state = %s new_state = %s\n", __func__,
@@ -4202,6 +4209,7 @@ static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
	struct snd_soc_card *card = rtd->card;
	struct snd_soc_card *card = rtd->card;
	struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
	struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
	struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
	struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
	int ret_pinctrl = 0;


	dev_dbg(rtd->card->dev,
	dev_dbg(rtd->card->dev,
		"%s: substream = %s  stream = %d, dai name %s, dai ID %d\n",
		"%s: substream = %s  stream = %d, dai name %s, dai ID %d\n",
@@ -4216,12 +4224,10 @@ static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
		goto err;
		goto err;
	}
	}
	if (index == QUAT_MI2S) {
	if (index == QUAT_MI2S) {
		ret = msm_set_pinctrl(pinctrl_info, STATE_MI2S_ACTIVE);
		ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_MI2S_ACTIVE);
		if (ret) {
		if (ret_pinctrl)
			pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
			pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
				__func__, ret);
				__func__, ret_pinctrl);
			goto err;
		}
	}
	}
	/*
	/*
	 * Muxtex protection in case the same MI2S
	 * Muxtex protection in case the same MI2S
@@ -4278,6 +4284,7 @@ static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
	struct snd_soc_card *card = rtd->card;
	struct snd_soc_card *card = rtd->card;
	struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
	struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
	struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
	struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
	int ret_pinctrl = 0;


	pr_debug("%s(): substream = %s  stream = %d\n", __func__,
	pr_debug("%s(): substream = %s  stream = %d\n", __func__,
		 substream->name, substream->stream);
		 substream->name, substream->stream);
@@ -4298,10 +4305,10 @@ static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
	mutex_unlock(&mi2s_intf_conf[index].lock);
	mutex_unlock(&mi2s_intf_conf[index].lock);


	if (index == QUAT_MI2S) {
	if (index == QUAT_MI2S) {
		ret = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
		ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
		if (ret)
		if (ret_pinctrl)
			pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
			pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
				__func__, ret);
				__func__, ret_pinctrl);
	}
	}
}
}