Skip to content

Commit

Permalink
ASoC: codecs: wcd938x: fix incorrect used of portid
Browse files Browse the repository at this point in the history
commit c5c1546 upstream.

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: e8ba1e0 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Srinivas-Kandagatla authored and gregkh committed Feb 8, 2022
1 parent f114fd6 commit 9167f27
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sound/soc/codecs/wcd938x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,14 +1432,10 @@ static int wcd938x_sdw_connect_port(struct wcd938x_sdw_ch_info *ch_info,
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],
&wcd->port_config[port_num],
&wcd->port_config[port_num - 1],
enable);
}

Expand Down Expand Up @@ -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_sdw_priv *wcd;
int value = ucontrol->value.integer.value[0];
int portidx;
struct soc_mixer_control *mc;
bool hphr;

Expand All @@ -2606,10 +2603,12 @@ static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
else
wcd938x->comp1_enable = value;

portidx = wcd->ch_info[mc->reg].port_num;

if (value)
wcd938x_connect_port(wcd, mc->reg, true);
wcd938x_connect_port(wcd, portidx, mc->reg, true);
else
wcd938x_connect_port(wcd, mc->reg, false);
wcd938x_connect_port(wcd, portidx, mc->reg, false);

return 0;
}
Expand Down Expand Up @@ -2882,9 +2881,11 @@ static int wcd938x_get_swr_port(struct snd_kcontrol *kcontrol,
struct wcd938x_sdw_priv *wcd;
struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value;
int dai_id = mixer->shift;
int portidx = mixer->reg;
int portidx, ch_idx = mixer->reg;


wcd = wcd938x->sdw_priv[dai_id];
portidx = wcd->ch_info[ch_idx].port_num;

ucontrol->value.integer.value[0] = wcd->port_enable[portidx];

Expand All @@ -2899,20 +2900,22 @@ static int wcd938x_set_swr_port(struct snd_kcontrol *kcontrol,
struct wcd938x_sdw_priv *wcd;
struct soc_mixer_control *mixer =
(struct soc_mixer_control *)kcontrol->private_value;
int portidx = mixer->reg;
int ch_idx = mixer->reg;
int portidx;
int dai_id = mixer->shift;
bool enable;

wcd = wcd938x->sdw_priv[dai_id];

portidx = wcd->ch_info[ch_idx].port_num;
if (ucontrol->value.integer.value[0])
enable = true;
else
enable = false;

wcd->port_enable[portidx] = enable;

wcd938x_connect_port(wcd, portidx, enable);
wcd938x_connect_port(wcd, portidx, ch_idx, enable);

return 0;

Expand Down

0 comments on commit 9167f27

Please sign in to comment.