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: Vignesh Kulothungan <vigneshk@codeaurora.org>
This commit is contained in:
Vignesh Kulothungan 2020-10-19 16:47:53 -07:00 • committed by Gerrit - the friendly Code Review server
commit d7c3e4fbe1

View file

@ -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",