ASoC: codecs: wcd938x: fix incorrect used of portid

Mixer controls have the channel id in mixer->reg, which is not same
as port id. port id should be derived from chan_info array.
So fix this. Without this, its possible that we could corrupt
struct wcd938x_sdw_priv by accessing port_map array out of range
with channel id instead of port id.

Fixes: e8ba1e05bd ("ASoC: codecs: wcd938x: add basic controls")
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20220126113549.8853-2-srinivas.kandagatla@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Srinivas Kandagatla 2022-01-26 11:35:46 +00:00 коммит произвёл Mark Brown
Родитель 4cf28e9ae6
Коммит c5c1546a65
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 24D68B725D5487D0
1 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -1432,14 +1432,10 @@ static int wcd938x_sdw_connect_port(struct wcd938x_sdw_ch_info *ch_info,
return 0; return 0;
} }
static int wcd938x_connect_port(struct wcd938x_sdw_priv *wcd, u8 ch_id, u8 enable) static int wcd938x_connect_port(struct wcd938x_sdw_priv *wcd, u8 port_num, u8 ch_id, u8 enable)
{ {
u8 port_num;
port_num = wcd->ch_info[ch_id].port_num;
return wcd938x_sdw_connect_port(&wcd->ch_info[ch_id], return wcd938x_sdw_connect_port(&wcd->ch_info[ch_id],
&wcd->port_config[port_num], &wcd->port_config[port_num - 1],
enable); enable);
} }
@ -2593,6 +2589,7 @@ static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
struct wcd938x_sdw_priv *wcd; struct wcd938x_sdw_priv *wcd;
int value = ucontrol->value.integer.value[0]; int value = ucontrol->value.integer.value[0];
int portidx;
struct soc_mixer_control *mc; struct soc_mixer_control *mc;
bool hphr; bool hphr;
@ -2606,10 +2603,12 @@ static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
else else
wcd938x->comp1_enable = value; wcd938x->comp1_enable = value;
portidx = wcd->ch_info[mc->reg].port_num;
if (value) if (value)
wcd938x_connect_port(wcd, mc->reg, true); wcd938x_connect_port(wcd, portidx, mc->reg, true);
else else
wcd938x_connect_port(wcd, mc->reg, false); wcd938x_connect_port(wcd, portidx, mc->reg, false);
return 0; return 0;
} }
@ -2882,9 +2881,11 @@ static int wcd938x_get_swr_port(struct snd_kcontrol *kcontrol,
struct wcd938x_sdw_priv *wcd; struct wcd938x_sdw_priv *wcd;
struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value;
int dai_id = mixer->shift; int dai_id = mixer->shift;
int portidx = mixer->reg; int portidx, ch_idx = mixer->reg;
wcd = wcd938x->sdw_priv[dai_id]; wcd = wcd938x->sdw_priv[dai_id];
portidx = wcd->ch_info[ch_idx].port_num;
ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; ucontrol->value.integer.value[0] = wcd->port_enable[portidx];
@ -2899,12 +2900,14 @@ static int wcd938x_set_swr_port(struct snd_kcontrol *kcontrol,
struct wcd938x_sdw_priv *wcd; struct wcd938x_sdw_priv *wcd;
struct soc_mixer_control *mixer = struct soc_mixer_control *mixer =
(struct soc_mixer_control *)kcontrol->private_value; (struct soc_mixer_control *)kcontrol->private_value;
int portidx = mixer->reg; int ch_idx = mixer->reg;
int portidx;
int dai_id = mixer->shift; int dai_id = mixer->shift;
bool enable; bool enable;
wcd = wcd938x->sdw_priv[dai_id]; wcd = wcd938x->sdw_priv[dai_id];
portidx = wcd->ch_info[ch_idx].port_num;
if (ucontrol->value.integer.value[0]) if (ucontrol->value.integer.value[0])
enable = true; enable = true;
else else
@ -2912,7 +2915,7 @@ static int wcd938x_set_swr_port(struct snd_kcontrol *kcontrol,
wcd->port_enable[portidx] = enable; wcd->port_enable[portidx] = enable;
wcd938x_connect_port(wcd, portidx, enable); wcd938x_connect_port(wcd, portidx, ch_idx, enable);
return 0; return 0;