712cdac5dd0505e545ef8c49c3961c66d9ecf6ee
[openwrt/openwrt.git] / target / linux / at91 / patches-5.10 / 127-regulator-core-validate-selector-against-linear_min_.patch
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
5 linear_min_sel
6
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.
12
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>
16 ---
17 drivers/regulator/core.c | 9 +++++++--
18 drivers/regulator/helpers.c | 3 ++-
19 2 files changed, 9 insertions(+), 3 deletions(-)
20
21 --- a/drivers/regulator/core.c
22 +++ b/drivers/regulator/core.c
23 @@ -2987,7 +2987,8 @@ static int _regulator_list_voltage(struc
24 return rdev->desc->fixed_uV;
25
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)
30 return -EINVAL;
31 if (lock)
32 regulator_lock(rdev);
33 @@ -3138,7 +3139,8 @@ int regulator_list_hardware_vsel(struct
34 struct regulator_dev *rdev = regulator->rdev;
35 const struct regulator_ops *ops = rdev->desc->ops;
36
37 - if (selector >= rdev->desc->n_voltages)
38 + if (selector >= rdev->desc->n_voltages ||
39 + selector < rdev->desc->linear_min_sel)
40 return -EINVAL;
41 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
42 return -EOPNOTSUPP;
43 @@ -4061,6 +4063,9 @@ int regulator_set_voltage_time(struct re
44
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)
48 + continue;
49 +
50 voltage = regulator_list_voltage(regulator, i);
51 if (voltage < 0)
52 return -EINVAL;
53 --- a/drivers/regulator/helpers.c
54 +++ b/drivers/regulator/helpers.c
55 @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct
56 return -EINVAL;
57 }
58
59 - if (selector >= rdev->desc->n_voltages)
60 + if (selector >= rdev->desc->n_voltages ||
61 + selector < rdev->desc->linear_min_sel)
62 return -EINVAL;
63
64 return rdev->desc->volt_table[selector];