at91: add kernel support for sama7g5 soc
[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 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
22 index 043b5f63b94a..dfdd42b9d773 100644
23 --- a/drivers/regulator/core.c
24 +++ b/drivers/regulator/core.c
25 @@ -2984,7 +2984,8 @@ static int _regulator_list_voltage(struct regulator_dev *rdev,
26 return rdev->desc->fixed_uV;
27
28 if (ops->list_voltage) {
29 - if (selector >= rdev->desc->n_voltages)
30 + if (selector >= rdev->desc->n_voltages ||
31 + selector < rdev->desc->linear_min_sel)
32 return -EINVAL;
33 if (lock)
34 regulator_lock(rdev);
35 @@ -3135,7 +3136,8 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
36 struct regulator_dev *rdev = regulator->rdev;
37 const struct regulator_ops *ops = rdev->desc->ops;
38
39 - if (selector >= rdev->desc->n_voltages)
40 + if (selector >= rdev->desc->n_voltages ||
41 + selector < rdev->desc->linear_min_sel)
42 return -EINVAL;
43 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
44 return -EOPNOTSUPP;
45 @@ -4058,6 +4060,9 @@ int regulator_set_voltage_time(struct regulator *regulator,
46
47 for (i = 0; i < rdev->desc->n_voltages; i++) {
48 /* We only look for exact voltage matches here */
49 + if (i < rdev->desc->linear_min_sel)
50 + continue;
51 +
52 voltage = regulator_list_voltage(regulator, i);
53 if (voltage < 0)
54 return -EINVAL;
55 diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
56 index e4bb09bbd3fa..974f1a63993d 100644
57 --- a/drivers/regulator/helpers.c
58 +++ b/drivers/regulator/helpers.c
59 @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct regulator_dev *rdev,
60 return -EINVAL;
61 }
62
63 - if (selector >= rdev->desc->n_voltages)
64 + if (selector >= rdev->desc->n_voltages ||
65 + selector < rdev->desc->linear_min_sel)
66 return -EINVAL;
67
68 return rdev->desc->volt_table[selector];
69 --
70 2.32.0
71