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

Commit d7c3e4fb authored by Vignesh Kulothungan's avatar Vignesh Kulothungan Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: codecs: add null check before use



Add null check for swr dmic component and swr_dmic_priv
before use.
Add array bounds check for slave port index before
accessing the array.

Change-Id: I57cc860e69d75385434822b1975d869d12717de4
Signed-off-by: default avatarVignesh Kulothungan <vigneshk@codeaurora.org>
parent 19df8856
Loading
Loading
Loading
Loading
+36 −4
Original line number Diff line number Diff line
@@ -130,9 +130,20 @@ static int swr_dmic_tx_master_port_get(struct snd_kcontrol *kcontrol,
{
	struct snd_soc_component *component =
				snd_soc_kcontrol_component(kcontrol);
	struct swr_dmic_priv *swr_dmic = snd_soc_component_get_drvdata(component);
	struct swr_dmic_priv *swr_dmic = NULL;
	int ret = 0;
	int slave_port_idx;
	unsigned int slave_port_idx = SWR_DMIC_MAX_PORTS;

	if (NULL == component) {
		pr_err("%s: swr dmic component is NULL\n", __func__);
		return -EINVAL;
	}

	swr_dmic = snd_soc_component_get_drvdata(component);
	if (NULL == swr_dmic) {
		pr_err("%s: swr_dmic_priv is NULL\n", __func__);
		return -EINVAL;
	}

	ret = swr_dmic_tx_get_slave_port_type_idx(kcontrol->id.name,
							&slave_port_idx);
@@ -141,6 +152,11 @@ static int swr_dmic_tx_master_port_get(struct snd_kcontrol *kcontrol,
		return ret;
	}

	if (slave_port_idx >= SWR_DMIC_MAX_PORTS) {
		pr_err("%s: invalid slave port id\n", __func__);
		return -EINVAL;
	}

	ucontrol->value.integer.value[0] =
			swr_dmic_get_master_port_val(
				swr_dmic->tx_master_port_map[slave_port_idx]);
@@ -156,9 +172,20 @@ static int swr_dmic_tx_master_port_put(struct snd_kcontrol *kcontrol,
{
	struct snd_soc_component *component =
				snd_soc_kcontrol_component(kcontrol);
	struct swr_dmic_priv *swr_dmic = snd_soc_component_get_drvdata(component);
	struct swr_dmic_priv *swr_dmic = NULL;
	int ret = 0;
	int slave_port_idx;
	unsigned int slave_port_idx = SWR_DMIC_MAX_PORTS;

	if (NULL == component) {
		pr_err("%s: swr dmic component is NULL\n", __func__);
		return -EINVAL;
	}

	swr_dmic = snd_soc_component_get_drvdata(component);
	if (NULL == swr_dmic) {
		pr_err("%s: swr_dmic_priv is NULL\n", __func__);
		return -EINVAL;
	}

	ret  = swr_dmic_tx_get_slave_port_type_idx(kcontrol->id.name,
							&slave_port_idx);
@@ -167,6 +194,11 @@ static int swr_dmic_tx_master_port_put(struct snd_kcontrol *kcontrol,
		return ret;
	}

	if (slave_port_idx >= SWR_DMIC_MAX_PORTS) {
		pr_err("%s: invalid slave port id\n", __func__);
		return -EINVAL;
	}

	swr_dmic->tx_master_port_map[slave_port_idx] =
		swr_master_channel_map[ucontrol->value.enumerated.item[0]];
	dev_dbg(component->dev, "%s: slv port id: %d, master_port_type: %d\n",