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

Commit 443aa424 authored by Aditya Bavanari's avatar Aditya Bavanari Committed by Gerrit - the friendly Code Review server
Browse files

asoc: codecs: wcd934x: Add NULL checks for mbhc



Add NULL checks for mbhc in tavil driver to avoid
NULL pointer dereferences when MBHC is not supported.

Change-Id: I43bfd062af6048486256f744bd028b27fedc7f53
Signed-off-by: default avatarAditya Bavanari <abavanar@codeaurora.org>
parent 1235f2b9
Loading
Loading
Loading
Loading
+49 −36
Original line number Diff line number Diff line
@@ -2340,6 +2340,7 @@ static int tavil_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
		break;
	case SND_SOC_DAPM_PRE_PMD:
		tavil_ocp_control(codec, false);
		if (tavil->mbhc)
			blocking_notifier_call_chain(&tavil->mbhc->notifier,
						     WCD_EVENT_PRE_HPHR_PA_OFF,
						     &tavil->mbhc->wcd_mbhc);
@@ -2366,6 +2367,7 @@ static int tavil_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
		else
			usleep_range(5000, 5100);
		tavil_codec_override(codec, tavil->hph_mode, event);
		if (tavil->mbhc)
			blocking_notifier_call_chain(&tavil->mbhc->notifier,
					WCD_EVENT_POST_HPHR_PA_OFF,
					&tavil->mbhc->wcd_mbhc);
@@ -2496,6 +2498,7 @@ static int tavil_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
		break;
	case SND_SOC_DAPM_PRE_PMD:
		tavil_ocp_control(codec, false);
		if (tavil->mbhc)
			blocking_notifier_call_chain(&tavil->mbhc->notifier,
						     WCD_EVENT_PRE_HPHL_PA_OFF,
						     &tavil->mbhc->wcd_mbhc);
@@ -2524,6 +2527,7 @@ static int tavil_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
		else
			usleep_range(5000, 5100);
		tavil_codec_override(codec, tavil->hph_mode, event);
		if (tavil->mbhc)
			blocking_notifier_call_chain(&tavil->mbhc->notifier,
						WCD_EVENT_POST_HPHL_PA_OFF,
						&tavil->mbhc->wcd_mbhc);
@@ -5228,6 +5232,7 @@ static void tavil_codec_hph_reg_recover(struct tavil_priv *tavil,
	int i;
	unsigned int reg;

	if (tavil->mbhc)
		blocking_notifier_call_chain(&tavil->mbhc->notifier,
					     WCD_EVENT_OCP_OFF,
					     &tavil->mbhc->wcd_mbhc);
@@ -5340,12 +5345,14 @@ static void tavil_codec_hph_reg_recover(struct tavil_priv *tavil,
	}

end:
	if (tavil->mbhc) {
		tavil->mbhc->is_hph_recover = true;
		blocking_notifier_call_chain(
				&tavil->mbhc->notifier,
				WCD_EVENT_OCP_ON,
				&tavil->mbhc->wcd_mbhc);
	}
}

static int tavil_codec_reset_hph_registers(struct snd_soc_dapm_widget *w,
					   struct snd_kcontrol *kcontrol,
@@ -5387,6 +5394,7 @@ static int tavil_codec_reset_hph_registers(struct snd_soc_dapm_widget *w,
		} else {
			dev_dbg(codec->dev, "%s: cache and hw reg are same\n",
				__func__);
			if (tavil->mbhc)
				tavil->mbhc->is_hph_recover = false;
		}
		break;
@@ -10093,6 +10101,7 @@ static int tavil_device_down(struct wcd9xxx *wcd9xxx)
		priv->dai[count].bus_down_in_recovery = true;
	snd_event_notify(priv->dev->parent, SND_EVENT_DOWN);

	if (priv->mbhc)
		priv->mbhc->wcd_mbhc.deinit_in_progress = true;
	if (delayed_work_pending(&priv->spk_anc_dwork.dwork))
		cancel_delayed_work(&priv->spk_anc_dwork.dwork);
@@ -10108,12 +10117,15 @@ static int tavil_device_down(struct wcd9xxx *wcd9xxx)
	}
	if (delayed_work_pending(&priv->power_gate_work))
		cancel_delayed_work_sync(&priv->power_gate_work);
	if (priv->mbhc) {
		if (delayed_work_pending(&priv->mbhc->wcd_mbhc.mbhc_btn_dwork)) {
		ret = cancel_delayed_work(&priv->mbhc->wcd_mbhc.mbhc_btn_dwork);
			ret = cancel_delayed_work(
					&priv->mbhc->wcd_mbhc.mbhc_btn_dwork);
			if (ret)
				priv->mbhc->wcd_mbhc.mbhc_cb->lock_sleep
						(&priv->mbhc->wcd_mbhc, false);
		}
	}

	if (priv->swr.ctrl_data) {
		if (is_snd_event_fwk_enabled())
@@ -10196,6 +10208,7 @@ static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx)
		dev_err(codec->dev, "%s: invalid pdata\n", __func__);

	/* Initialize MBHC module */
	if (tavil->mbhc) {
		mbhc = &tavil->mbhc->wcd_mbhc;
		ret = tavil_mbhc_post_ssr_init(tavil->mbhc, codec);
		if (ret) {
@@ -10205,7 +10218,7 @@ static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx)
		} else {
			tavil_mbhc_hs_detect(codec, mbhc->mbhc_cfg);
		}

	}
	/* DSD initialization */
	ret = tavil_dsd_post_ssr_init(tavil->dsd_config);
	if (ret)