ASoC: ops: Correct bounds check for second channel on SX controls
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Fri, 25 Nov 2022 16:23:47 +0000 (16:23 +0000)
committerMark Brown <broonie@kernel.org>
Fri, 25 Nov 2022 16:29:33 +0000 (16:29 +0000)
Currently the check against the max value for the control is being
applied after the value has had the minimum applied and been masked. But
the max value simply indicates the number of volume levels on an SX
control, and as such should just be applied on the raw value.

Fixes: 97eea946b939 ("ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx()")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20221125162348.1288005-1-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-ops.c

index 1970bda..55b009d 100644 (file)
@@ -464,16 +464,15 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
        ret = err;
 
        if (snd_soc_volsw_is_stereo(mc)) {
-               unsigned int val2;
-
-               val_mask = mask << rshift;
-               val2 = (ucontrol->value.integer.value[1] + min) & mask;
+               unsigned int val2 = ucontrol->value.integer.value[1];
 
                if (mc->platform_max && val2 > mc->platform_max)
                        return -EINVAL;
                if (val2 > max)
                        return -EINVAL;
 
+               val_mask = mask << rshift;
+               val2 = (val2 + min) & mask;
                val2 = val2 << rshift;
 
                err = snd_soc_component_update_bits(component, reg2, val_mask,