Skip to content

Commit

Permalink
ASoC: ops: Check for negative values before reading them
Browse files Browse the repository at this point in the history
The controls allow inputs to be specified as negative but our manipulating
them into register fields need to be done on unsigned variables so the
checks for negative numbers weren't taking effect properly. Do the checks
for negative values on the variable in the ABI struct rather than on our
local unsigned copy.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220128192443.3504823-1-broonie@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Mark Brown committed Jan 28, 2022
1 parent 4c38f87 commit 1601033
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sound/soc/soc-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,26 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
if (sign_bit)
mask = BIT(sign_bit + 1) - 1;

if (ucontrol->value.integer.value[0] < 0)
return -EINVAL;
val = ucontrol->value.integer.value[0];
if (mc->platform_max && val > mc->platform_max)
return -EINVAL;
if (val > max - min)
return -EINVAL;
if (val < 0)
return -EINVAL;
val = (val + min) & mask;
if (invert)
val = max - val;
val_mask = mask << shift;
val = val << shift;
if (snd_soc_volsw_is_stereo(mc)) {
if (ucontrol->value.integer.value[1] < 0)
return -EINVAL;
val2 = ucontrol->value.integer.value[1];
if (mc->platform_max && val2 > mc->platform_max)
return -EINVAL;
if (val2 > max - min)
return -EINVAL;
if (val2 < 0)
return -EINVAL;
val2 = (val2 + min) & mask;
if (invert)
val2 = max - val2;
Expand Down Expand Up @@ -423,13 +423,13 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
int err = 0;
unsigned int val, val_mask;

if (ucontrol->value.integer.value[0] < 0)
return -EINVAL;
val = ucontrol->value.integer.value[0];
if (mc->platform_max && val > mc->platform_max)
return -EINVAL;
if (val > max - min)
return -EINVAL;
if (val < 0)
return -EINVAL;
val_mask = mask << shift;
val = (val + min) & mask;
val = val << shift;
Expand Down

0 comments on commit 1601033

Please sign in to comment.