Skip to content

Commit

Permalink
ASoC: Fix overflow bug in SOC_DOUBLE_R_SX_TLV
Browse files Browse the repository at this point in the history
When SX_TLV widgets are read, if the gain is set to a value below 0dB,
the mixer control is erroniously read as being at maximum volume.

The value read out of the CODEC register is never sign-extended, and
when the minimum value is subtracted (read; added, since the minimum is
negative) the result is a number greater than the maximum allowed value
for the control, and hence it saturates.

Solution: Mask the result so that it "wraps around", emulating
sign-extension.

Signed-off-by: Stuart Longland <redhatter@gentoo.org>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Stuart Longland authored and Mark Brown committed Jun 19, 2010
1 parent 4379320 commit 20630c7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2396,8 +2396,8 @@ int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
int val = snd_soc_read(codec, mc->reg) & mask;
int valr = snd_soc_read(codec, mc->rreg) & mask;

ucontrol->value.integer.value[0] = ((val & 0xff)-min);
ucontrol->value.integer.value[1] = ((valr & 0xff)-min);
ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
Expand Down

0 comments on commit 20630c7

Please sign in to comment.