kernel: bump 5.10 to 5.10.121
[openwrt/staging/ansuel.git] / target / linux / at91 / patches-5.10 / 129-regulator-core-return-zero-for-selectors-lower-than-.patch
1 From 0e933ffc049a0e181b5a6c3af1933976d6959ba9 Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Wed, 25 Nov 2020 19:25:47 +0200
4 Subject: [PATCH 129/247] regulator: core: return zero for selectors lower than
5 linear_min_sel
6
7 Selectors lower than linear_min_sel should not be considered invalid.
8 Thus return zero in case _regulator_list_voltage(),
9 regulator_list_hardware_vsel() or regulator_list_voltage_table()
10 receives such selectors as argument.
11
12 Fixes: bdcd1177578c ("regulator: core: validate selector against linear_min_sel")
13 Reported-by: Jon Hunter <jonathanh@nvidia.com>
14 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
15 Link: https://lore.kernel.org/r/1606325147-606-1-git-send-email-claudiu.beznea@microchip.com
16 Signed-off-by: Mark Brown <broonie@kernel.org>
17 ---
18 drivers/regulator/core.c | 10 ++++++----
19 drivers/regulator/helpers.c | 5 +++--
20 2 files changed, 9 insertions(+), 6 deletions(-)
21
22 --- a/drivers/regulator/core.c
23 +++ b/drivers/regulator/core.c
24 @@ -2987,9 +2987,10 @@ static int _regulator_list_voltage(struc
25 return rdev->desc->fixed_uV;
26
27 if (ops->list_voltage) {
28 - if (selector >= rdev->desc->n_voltages ||
29 - selector < rdev->desc->linear_min_sel)
30 + if (selector >= rdev->desc->n_voltages)
31 return -EINVAL;
32 + if (selector < rdev->desc->linear_min_sel)
33 + return 0;
34 if (lock)
35 regulator_lock(rdev);
36 ret = ops->list_voltage(rdev, selector);
37 @@ -3139,9 +3140,10 @@ int regulator_list_hardware_vsel(struct
38 struct regulator_dev *rdev = regulator->rdev;
39 const struct regulator_ops *ops = rdev->desc->ops;
40
41 - if (selector >= rdev->desc->n_voltages ||
42 - selector < rdev->desc->linear_min_sel)
43 + if (selector >= rdev->desc->n_voltages)
44 return -EINVAL;
45 + if (selector < rdev->desc->linear_min_sel)
46 + return 0;
47 if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
48 return -EOPNOTSUPP;
49
50 --- a/drivers/regulator/helpers.c
51 +++ b/drivers/regulator/helpers.c
52 @@ -647,9 +647,10 @@ int regulator_list_voltage_table(struct
53 return -EINVAL;
54 }
55
56 - if (selector >= rdev->desc->n_voltages ||
57 - selector < rdev->desc->linear_min_sel)
58 + if (selector >= rdev->desc->n_voltages)
59 return -EINVAL;
60 + if (selector < rdev->desc->linear_min_sel)
61 + return 0;
62
63 return rdev->desc->volt_table[selector];
64 }