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

Commit f06b79bf authored by Laxminath Kasam's avatar Laxminath Kasam
Browse files

ASoC: msm8x16-wcd: Avoid null pointer spmi access



SPMI devices for PMIC digital and analog codec
are registered one after other whenever probe happens.
Say first digital slave is registered, it also registers
codec to ALSA core. There is a chance that codec probe
is triggered even before PMIC analog slave device is
registered. In codec probe, when try to access
any SPMI register related to analog slave, it will crash.
Handle this in probe function to avoid the crash.

CRs-Fixed: 969220
Change-Id: If63831774960ccb2f62cc4e9b855ccee0ba6f4ab
Signed-off-by: default avatarLaxminath Kasam <lkasam@codeaurora.org>
parent b7ca2f4c
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -5841,6 +5841,7 @@ static int msm8x16_wcd_spmi_probe(struct spmi_device *spmi)
	struct msm8x16_wcd_pdata *pdata;
	struct resource *wcd_resource;
	int adsp_state;
	static int spmi_dev_registered_cnt;

	dev_dbg(&spmi->dev, "%s(%d):slave ID = 0x%x\n",
		__func__, __LINE__,  spmi->sid);
@@ -5878,7 +5879,8 @@ static int msm8x16_wcd_spmi_probe(struct spmi_device *spmi)
		dev_dbg(&spmi->dev,
				"%s: irq initialization passed\n", __func__);
	}
		goto rtn;
		spmi_dev_registered_cnt++;
		goto register_codec;
	default:
		ret = -EINVAL;
		goto rtn;
@@ -5940,17 +5942,24 @@ static int msm8x16_wcd_spmi_probe(struct spmi_device *spmi)
		goto err_supplies;
	}
	dev_set_drvdata(&spmi->dev, msm8x16);

	ret = snd_soc_register_codec(&spmi->dev, &soc_codec_dev_msm8x16_wcd,
	spmi_dev_registered_cnt++;
register_codec:
	if ((spmi_dev_registered_cnt == MAX_MSM8X16_WCD_DEVICE) && (!ret)) {
		if (msm8x16_wcd_modules[0].spmi) {
			ret = snd_soc_register_codec(
					&msm8x16_wcd_modules[0].spmi->dev,
					&soc_codec_dev_msm8x16_wcd,
					msm8x16_wcd_i2s_dai,
					ARRAY_SIZE(msm8x16_wcd_i2s_dai));
			if (ret) {
				dev_err(&spmi->dev,
				"%s:snd_soc_register_codec failed with error %d\n",
				__func__, ret);
	} else {
		goto rtn;
				goto err_supplies;
			}
		}
	}
	return ret;
err_supplies:
	msm8x16_wcd_disable_supplies(msm8x16, pdata);
err_codec: