Skip to content

Commit 1601033

Browse files
committed
ASoC: ops: Check for negative values before reading them
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 4c38f87 commit 1601033

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sound/soc/soc-ops.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,26 +316,26 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
316316
if (sign_bit)
317317
mask = BIT(sign_bit + 1) - 1;
318318

319+
if (ucontrol->value.integer.value[0] < 0)
320+
return -EINVAL;
319321
val = ucontrol->value.integer.value[0];
320322
if (mc->platform_max && val > mc->platform_max)
321323
return -EINVAL;
322324
if (val > max - min)
323325
return -EINVAL;
324-
if (val < 0)
325-
return -EINVAL;
326326
val = (val + min) & mask;
327327
if (invert)
328328
val = max - val;
329329
val_mask = mask << shift;
330330
val = val << shift;
331331
if (snd_soc_volsw_is_stereo(mc)) {
332+
if (ucontrol->value.integer.value[1] < 0)
333+
return -EINVAL;
332334
val2 = ucontrol->value.integer.value[1];
333335
if (mc->platform_max && val2 > mc->platform_max)
334336
return -EINVAL;
335337
if (val2 > max - min)
336338
return -EINVAL;
337-
if (val2 < 0)
338-
return -EINVAL;
339339
val2 = (val2 + min) & mask;
340340
if (invert)
341341
val2 = max - val2;
@@ -423,13 +423,13 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
423423
int err = 0;
424424
unsigned int val, val_mask;
425425

426+
if (ucontrol->value.integer.value[0] < 0)
427+
return -EINVAL;
426428
val = ucontrol->value.integer.value[0];
427429
if (mc->platform_max && val > mc->platform_max)
428430
return -EINVAL;
429431
if (val > max - min)
430432
return -EINVAL;
431-
if (val < 0)
432-
return -EINVAL;
433433
val_mask = mask << shift;
434434
val = (val + min) & mask;
435435
val = val << shift;

0 commit comments

Comments
 (0)