asoc: lpass-cdc: Add check for array bound overflow

In lpass_cdc_wsa_macro_config_compander function,
add check for wsa_sys_gain array's index to make sure
it won't go out of bound.

Change-Id: I9d8512726de959e7a0d9e875e966140d70412e25
Signed-off-by: Deepali Jindal <quic_deepjind@quicinc.com>
This commit is contained in:
Deepali Jindal
2023-06-20 21:51:05 +05:30
parent 44f00dc545
commit 3daac9507a
2 changed files with 16 additions and 2 deletions

View File

@@ -1379,6 +1379,7 @@ static int lpass_cdc_wsa2_macro_config_compander(struct snd_soc_component *compo
struct lpass_cdc_wsa2_macro_priv *wsa2_priv = NULL;
struct lpass_cdc_comp_setting *comp_settings = NULL;
u16 mode = 0;
u16 index = 0;
int sys_gain, bat_cfg, sys_gain_int, upper_gain, lower_gain;
if (!lpass_cdc_wsa2_macro_get_data(component, &wsa2_dev, &wsa2_priv, __func__))
@@ -1409,7 +1410,13 @@ static int lpass_cdc_wsa2_macro_config_compander(struct snd_soc_component *compo
/* If System has battery configuration */
if (wsa2_priv->wsa2_bat_cfg[comp]) {
sys_gain = wsa2_priv->wsa2_sys_gain[comp * 2 + wsa2_priv->wsa2_spkrrecv];
index = (comp * 2) + wsa2_priv->wsa2_spkrrecv;
if (index >= (2 * (LPASS_CDC_WSA2_MACRO_RX1 + 1))) {
dev_err(component->dev, "%s: Invalid index: %d\n",
__func__, index);
return -EINVAL;
}
sys_gain = wsa2_priv->wsa2_sys_gain[index];
bat_cfg = wsa2_priv->wsa2_bat_cfg[comp];
/* Convert enum to value and
* multiply all values by 10 to avoid float