1 From 3aee4f22ed0a22d3d6d22fc49812c03d876c7637 Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Fri, 13 Nov 2020 17:21:05 +0200
4 Subject: [PATCH 127/247] regulator: core: validate selector against
7 There are regulators who's min selector is not zero. Selectors loops
8 (looping b/w zero and regulator::desc::n_voltages) might throw errors
9 because invalid selectors are used (lower than
10 regulator::desc::linear_min_sel). For this situations validate selectors
11 against regulator::desc::linear_min_sel.
13 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
14 Link: https://lore.kernel.org/r/1605280870-32432-2-git-send-email-claudiu.beznea@microchip.com
15 Signed-off-by: Mark Brown <broonie@kernel.org>
17 drivers/regulator/core.c | 9 +++++++--
18 drivers/regulator/helpers.c | 3 ++-
19 2 files changed, 9 insertions(+), 3 deletions(-)
21 --- a/drivers/regulator/core.c
22 +++ b/drivers/regulator/core.c
23 @@ -2992,7 +2992,8 @@ static int _regulator_list_voltage(struc
24 return rdev->desc->fixed_uV;
26 if (ops->list_voltage) {
27 - if (selector >= rdev->desc->n_voltages)
28 + if (selector >= rdev->desc->n_voltages ||
29 + selector < rdev->desc->linear_min_sel)
33 @@ -3143,7 +3144,8 @@ int regulator_list_hardware_vsel(struct
34 struct regulator_dev *rdev = regulator->rdev;
35 const struct regulator_ops *ops = rdev->desc->ops;
37 - if (selector >= rdev->desc->n_voltages)
38 + if (selector >= rdev->desc->n_voltages ||
39 + selector < rdev->desc->linear_min_sel)
41 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
43 @@ -4066,6 +4068,9 @@ int regulator_set_voltage_time(struct re
45 for (i = 0; i < rdev->desc->n_voltages; i++) {
46 /* We only look for exact voltage matches here */
47 + if (i < rdev->desc->linear_min_sel)
50 voltage = regulator_list_voltage(regulator, i);
53 --- a/drivers/regulator/helpers.c
54 +++ b/drivers/regulator/helpers.c
55 @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct
59 - if (selector >= rdev->desc->n_voltages)
60 + if (selector >= rdev->desc->n_voltages ||
61 + selector < rdev->desc->linear_min_sel)
64 return rdev->desc->volt_table[selector];