diff --git a/asoc/codecs/swr-dmic.c b/asoc/codecs/swr-dmic.c index 0729e56e3b..367f73a708 100644 --- a/asoc/codecs/swr-dmic.c +++ b/asoc/codecs/swr-dmic.c @@ -132,9 +132,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); @@ -143,6 +154,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]); @@ -158,9 +174,21 @@ 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; - unsigned int slave_port_idx = SWR_DMIC_MAX_PORTS, idx = 0; + unsigned int slave_port_idx = SWR_DMIC_MAX_PORTS; + unsigned int idx = 0; + + 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); @@ -169,6 +197,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; + } + idx = ucontrol->value.enumerated.item[0]; if (idx < 0 || idx >= ARRAY_SIZE(swr_master_channel_map)) return -EINVAL;