Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit af96efa6 authored by Tan Nayir's avatar Tan Nayir Committed by Michael Bestas
Browse files

ASoC: ops: Fix the bounds checking in snd_soc_put_volsw_sx and snd_soc_put_xr_sx

The $val in both functions has a range between 0 and an arbitrary limit
whereas the range specified with the $min and $max can start
from a negative number. To do the out of bound check correctly, the
$val must be added the $min offset.

Previous-discussion: https://lore.kernel.org/all/c2163c71-2f71-9011-3966-baeab8e8dc8f@gmail.com/


Fixes: 4f1e50d6a9cf9 ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx()")
Fixes: 4cf28e9ae6e2e ("ASoC: ops: Reject out of bounds values in snd_soc_put_xr_sx()")
Signed-off-by: default avatarTan Nayir <tannayir@gmail.com>
Change-Id: I8a220daaeb943a1933464f6914b1f175fdfaf5a8
parent cdf2f2b2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
	unsigned int val, val_mask, val2 = 0;

	val = ucontrol->value.integer.value[0];
	if (mc->platform_max && val > mc->platform_max)
	if (mc->platform_max && ((int)val + min) > mc->platform_max)
		return -EINVAL;
	if (val > max - min)
		return -EINVAL;
@@ -932,11 +932,12 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
	unsigned int invert = mc->invert;
	unsigned long mask = (1UL<<mc->nbits)-1;
	long max = mc->max;
	long min = mc->min;
	long val = ucontrol->value.integer.value[0];
	unsigned int i, regval, regmask;
	int err;

	if (val < mc->min || val > mc->max)
	if (val < mc->min || ((int)val + min) > mc->max)
		return -EINVAL;
	if (invert)
		val = max - val;