Skip to content

Commit aa22125

Browse files
committed
ASoC: ops: Validate input values in snd_soc_put_volsw_range()
Check that values written via snd_soc_put_volsw_range() are within the range advertised by the control, ensuring that we don't write out of spec values to the hardware. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 660564f commit aa22125

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

sound/soc/soc-ops.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,15 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
519519
unsigned int mask = (1 << fls(max)) - 1;
520520
unsigned int invert = mc->invert;
521521
unsigned int val, val_mask;
522-
int err, ret;
522+
int err, ret, tmp;
523+
524+
tmp = ucontrol->value.integer.value[0];
525+
if (tmp < 0)
526+
return -EINVAL;
527+
if (mc->platform_max && tmp > mc->platform_max)
528+
return -EINVAL;
529+
if (tmp > mc->max - mc->min + 1)
530+
return -EINVAL;
523531

524532
if (invert)
525533
val = (max - ucontrol->value.integer.value[0]) & mask;
@@ -534,6 +542,14 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
534542
ret = err;
535543

536544
if (snd_soc_volsw_is_stereo(mc)) {
545+
tmp = ucontrol->value.integer.value[1];
546+
if (tmp < 0)
547+
return -EINVAL;
548+
if (mc->platform_max && tmp > mc->platform_max)
549+
return -EINVAL;
550+
if (tmp > mc->max - mc->min + 1)
551+
return -EINVAL;
552+
537553
if (invert)
538554
val = (max - ucontrol->value.integer.value[1]) & mask;
539555
else

0 commit comments

Comments
 (0)