Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ab3100: fix off-by-one value range checking for voltage selector

We use voltage selector as an array index for typ_voltages.
Thus the valid range for voltage selector should be 0..voltages_len-1.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>

authored by

Axel Lin and committed by
Liam Girdwood
979da89a b37fa16e

+2 -2
+2 -2
drivers/regulator/ab3100.c
··· 286 286 { 287 287 struct ab3100_regulator *abreg = reg->reg_data; 288 288 289 - if (selector > abreg->voltages_len) 289 + if (selector >= abreg->voltages_len) 290 290 return -EINVAL; 291 291 return abreg->typ_voltages[selector]; 292 292 } ··· 318 318 regval &= 0xE0; 319 319 regval >>= 5; 320 320 321 - if (regval > abreg->voltages_len) { 321 + if (regval >= abreg->voltages_len) { 322 322 dev_err(&reg->dev, 323 323 "regulator register %02x contains an illegal voltage setting\n", 324 324 abreg->regreg);