[ammarfaizi2-block:broonie/sound/for-linus 179/181] sound/soc/soc-ops.c:324 snd_soc_put_volsw() warn: unsigned 'val' is never less than zero.

From: kernel test robot
Date: Wed Jan 26 2022 - 08:58:00 EST


tree: https://github.com/ammarfaizi2/linux-block broonie/sound/for-linus
head: 4cf28e9ae6e2e11a044be1bcbcfa1b0d8675fe4d
commit: 817f7c9335ec01e0f5e8caffc4f1dcd5e458a4c0 [179/181] ASoC: ops: Reject out of bounds values in snd_soc_put_volsw()
config: openrisc-randconfig-m031-20220124 (https://download.01.org/0day-ci/archive/20220126/202201262114.DuFfpPvs-lkp@xxxxxxxxx/config)
compiler: or1k-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

smatch warnings:
sound/soc/soc-ops.c:324 snd_soc_put_volsw() warn: unsigned 'val' is never less than zero.
sound/soc/soc-ops.c:337 snd_soc_put_volsw() warn: unsigned 'val2' is never less than zero.

vim +/val +324 sound/soc/soc-ops.c

285
286 /**
287 * snd_soc_put_volsw - single mixer put callback
288 * @kcontrol: mixer control
289 * @ucontrol: control element information
290 *
291 * Callback to set the value of a single mixer control, or a double mixer
292 * control that spans 2 registers.
293 *
294 * Returns 0 for success.
295 */
296 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
297 struct snd_ctl_elem_value *ucontrol)
298 {
299 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
300 struct soc_mixer_control *mc =
301 (struct soc_mixer_control *)kcontrol->private_value;
302 unsigned int reg = mc->reg;
303 unsigned int reg2 = mc->rreg;
304 unsigned int shift = mc->shift;
305 unsigned int rshift = mc->rshift;
306 int max = mc->max;
307 int min = mc->min;
308 unsigned int sign_bit = mc->sign_bit;
309 unsigned int mask = (1 << fls(max)) - 1;
310 unsigned int invert = mc->invert;
311 int err;
312 bool type_2r = false;
313 unsigned int val2 = 0;
314 unsigned int val, val_mask;
315
316 if (sign_bit)
317 mask = BIT(sign_bit + 1) - 1;
318
319 val = ucontrol->value.integer.value[0];
320 if (mc->platform_max && val > mc->platform_max)
321 return -EINVAL;
322 if (val > max - min)
323 return -EINVAL;
> 324 if (val < 0)
325 return -EINVAL;
326 val = (val + min) & mask;
327 if (invert)
328 val = max - val;
329 val_mask = mask << shift;
330 val = val << shift;
331 if (snd_soc_volsw_is_stereo(mc)) {
332 val2 = ucontrol->value.integer.value[1];
333 if (mc->platform_max && val2 > mc->platform_max)
334 return -EINVAL;
335 if (val2 > max - min)
336 return -EINVAL;
> 337 if (val2 < 0)
338 return -EINVAL;
339 val2 = (val2 + min) & mask;
340 if (invert)
341 val2 = max - val2;
342 if (reg == reg2) {
343 val_mask |= mask << rshift;
344 val |= val2 << rshift;
345 } else {
346 val2 = val2 << shift;
347 type_2r = true;
348 }
349 }
350 err = snd_soc_component_update_bits(component, reg, val_mask, val);
351 if (err < 0)
352 return err;
353
354 if (type_2r)
355 err = snd_soc_component_update_bits(component, reg2, val_mask,
356 val2);
357
358 return err;
359 }
360 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
361

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx