Просмотр исходного кода

asoc: update out of bound check for comp_mode.

updated the out of bound check for comp_mode
if any such occurence happens setting it to default mode.

Change-Id: Ie4a7275d45af6a96f1a2ec4b6ece6dc7a5dca464
Signed-off-by: Ganapathiraju Sarath Varma <[email protected]>
Ganapathiraju Sarath Varma 2 лет назад
Родитель
Сommit
c7d5b69be6

+ 8 - 2
asoc/codecs/lpass-cdc/lpass-cdc-wsa-macro.c

@@ -1373,7 +1373,7 @@ static int lpass_cdc_wsa_macro_config_compander(struct snd_soc_component *compon
 	if (!lpass_cdc_wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
 		return -EINVAL;
 
-	if (comp >= LPASS_CDC_WSA_MACRO_COMP_MAX) {
+	if (comp >= LPASS_CDC_WSA_MACRO_COMP_MAX || comp < 0) {
 		dev_err(component->dev, "%s: Invalid compander value: %d\n",
 					__func__, comp);
 		return -EINVAL;
@@ -1386,6 +1386,8 @@ static int lpass_cdc_wsa_macro_config_compander(struct snd_soc_component *compon
 		return 0;
 
 	mode = wsa_priv->comp_mode[comp];
+	if (mode >= G_MAX_DB || mode < 0)
+		mode = 0;
 	comp_ctl0_reg = LPASS_CDC_WSA_COMPANDER0_CTL0 +
 					(comp * LPASS_CDC_WSA_MACRO_RX_COMP_OFFSET);
 	comp_ctl8_reg = LPASS_CDC_WSA_COMPANDER0_CTL8 +
@@ -2416,7 +2418,11 @@ static int lpass_cdc_wsa_macro_comp_mode_put(struct snd_kcontrol *kcontrol,
 		idx = LPASS_CDC_WSA_MACRO_COMP1;
 	if (strnstr(kcontrol->id.name, "RX1", sizeof("WSA_RX1")))
 		idx = LPASS_CDC_WSA_MACRO_COMP2;
-	wsa_priv->comp_mode[idx] =  ucontrol->value.integer.value[0];
+
+	if (ucontrol->value.integer.value[0] < G_MAX_DB && ucontrol->value.integer.value[0] >= 0)
+		wsa_priv->comp_mode[idx] = ucontrol->value.integer.value[0];
+	else
+		return 0;
 
 	dev_dbg(component->dev, "%s: comp_mode = %d\n", __func__,
 		wsa_priv->comp_mode[idx]);

+ 14 - 1
asoc/codecs/lpass-cdc/lpass-cdc-wsa2-macro.c

@@ -1381,10 +1381,18 @@ static int lpass_cdc_wsa2_macro_config_compander(struct snd_soc_component *compo
 	dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
 		__func__, event, comp + 1, wsa2_priv->comp_enabled[comp]);
 
+	if (comp >= LPASS_CDC_WSA2_MACRO_COMP_MAX || comp < 0) {
+		dev_err(component->dev, "%s: Invalid compander value: %d\n",
+							__func__, comp);
+		return -EINVAL;
+	}
+
 	if (!wsa2_priv->comp_enabled[comp])
 		return 0;
 
 	mode = wsa2_priv->comp_mode[comp];
+	if (mode >= G_MAX_DB || mode < 0)
+		mode = 0;
 	comp_ctl0_reg = LPASS_CDC_WSA2_COMPANDER0_CTL0 +
 					(comp * LPASS_CDC_WSA2_MACRO_RX_COMP_OFFSET);
 	comp_ctl8_reg = LPASS_CDC_WSA2_COMPANDER0_CTL8 +
@@ -2415,7 +2423,12 @@ static int lpass_cdc_wsa2_macro_comp_mode_put(struct snd_kcontrol *kcontrol,
 		idx = LPASS_CDC_WSA2_MACRO_COMP1;
 	if (strnstr(kcontrol->id.name, "RX1", sizeof("WSA2_RX1")))
 		idx = LPASS_CDC_WSA2_MACRO_COMP2;
-	wsa2_priv->comp_mode[idx] =  ucontrol->value.integer.value[0];
+
+	if (ucontrol->value.integer.value[0] < G_MAX_DB &&
+						ucontrol->value.integer.value[0] >= 0)
+		wsa2_priv->comp_mode[idx] =  ucontrol->value.integer.value[0];
+	else
+		return 0;
 
 	dev_dbg(component->dev, "%s: comp_mode = %d\n", __func__,
 		wsa2_priv->comp_mode[idx]);