Skip to content

Commit c5c1546

Browse files
Srinivas-Kandagatlabroonie
authored andcommitted
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: e8ba1e0 ("ASoC: codecs: wcd938x: add basic controls") Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 4cf28e9 commit c5c1546

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

sound/soc/codecs/wcd938x.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,14 +1432,10 @@ static int wcd938x_sdw_connect_port(struct wcd938x_sdw_ch_info *ch_info,
14321432
return 0;
14331433
}
14341434

1435-
static int wcd938x_connect_port(struct wcd938x_sdw_priv *wcd, u8 ch_id, u8 enable)
1435+
static int wcd938x_connect_port(struct wcd938x_sdw_priv *wcd, u8 port_num, u8 ch_id, u8 enable)
14361436
{
1437-
u8 port_num;
1438-
1439-
port_num = wcd->ch_info[ch_id].port_num;
1440-
14411437
return wcd938x_sdw_connect_port(&wcd->ch_info[ch_id],
1442-
&wcd->port_config[port_num],
1438+
&wcd->port_config[port_num - 1],
14431439
enable);
14441440
}
14451441

@@ -2593,6 +2589,7 @@ static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
25932589
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
25942590
struct wcd938x_sdw_priv *wcd;
25952591
int value = ucontrol->value.integer.value[0];
2592+
int portidx;
25962593
struct soc_mixer_control *mc;
25972594
bool hphr;
25982595

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

2606+
portidx = wcd->ch_info[mc->reg].port_num;
2607+
26092608
if (value)
2610-
wcd938x_connect_port(wcd, mc->reg, true);
2609+
wcd938x_connect_port(wcd, portidx, mc->reg, true);
26112610
else
2612-
wcd938x_connect_port(wcd, mc->reg, false);
2611+
wcd938x_connect_port(wcd, portidx, mc->reg, false);
26132612

26142613
return 0;
26152614
}
@@ -2882,9 +2881,11 @@ static int wcd938x_get_swr_port(struct snd_kcontrol *kcontrol,
28822881
struct wcd938x_sdw_priv *wcd;
28832882
struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value;
28842883
int dai_id = mixer->shift;
2885-
int portidx = mixer->reg;
2884+
int portidx, ch_idx = mixer->reg;
2885+
28862886

28872887
wcd = wcd938x->sdw_priv[dai_id];
2888+
portidx = wcd->ch_info[ch_idx].port_num;
28882889

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

@@ -2899,20 +2900,22 @@ static int wcd938x_set_swr_port(struct snd_kcontrol *kcontrol,
28992900
struct wcd938x_sdw_priv *wcd;
29002901
struct soc_mixer_control *mixer =
29012902
(struct soc_mixer_control *)kcontrol->private_value;
2902-
int portidx = mixer->reg;
2903+
int ch_idx = mixer->reg;
2904+
int portidx;
29032905
int dai_id = mixer->shift;
29042906
bool enable;
29052907

29062908
wcd = wcd938x->sdw_priv[dai_id];
29072909

2910+
portidx = wcd->ch_info[ch_idx].port_num;
29082911
if (ucontrol->value.integer.value[0])
29092912
enable = true;
29102913
else
29112914
enable = false;
29122915

29132916
wcd->port_enable[portidx] = enable;
29142917

2915-
wcd938x_connect_port(wcd, portidx, enable);
2918+
wcd938x_connect_port(wcd, portidx, ch_idx, enable);
29162919

29172920
return 0;
29182921

0 commit comments

Comments
 (0)