regulator: core: validate selector against linear_min_sel
There are regulators who's min selector is not zero. Selectors loops (looping b/w zero and regulator::desc::n_voltages) might throw errors because invalid selectors are used (lower than regulator::desc::linear_min_sel). For this situations validate selectors against regulator::desc::linear_min_sel. Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Link: https://lore.kernel.org/r/1605280870-32432-2-git-send-email-claudiu.beznea@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Родитель
842f44806e
Коммит
bdcd117757
|
@ -2958,7 +2958,8 @@ static int _regulator_list_voltage(struct regulator_dev *rdev,
|
||||||
return rdev->desc->fixed_uV;
|
return rdev->desc->fixed_uV;
|
||||||
|
|
||||||
if (ops->list_voltage) {
|
if (ops->list_voltage) {
|
||||||
if (selector >= rdev->desc->n_voltages)
|
if (selector >= rdev->desc->n_voltages ||
|
||||||
|
selector < rdev->desc->linear_min_sel)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (lock)
|
if (lock)
|
||||||
regulator_lock(rdev);
|
regulator_lock(rdev);
|
||||||
|
@ -3109,7 +3110,8 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
|
||||||
struct regulator_dev *rdev = regulator->rdev;
|
struct regulator_dev *rdev = regulator->rdev;
|
||||||
const struct regulator_ops *ops = rdev->desc->ops;
|
const struct regulator_ops *ops = rdev->desc->ops;
|
||||||
|
|
||||||
if (selector >= rdev->desc->n_voltages)
|
if (selector >= rdev->desc->n_voltages ||
|
||||||
|
selector < rdev->desc->linear_min_sel)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
|
if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
@ -4032,6 +4034,9 @@ int regulator_set_voltage_time(struct regulator *regulator,
|
||||||
|
|
||||||
for (i = 0; i < rdev->desc->n_voltages; i++) {
|
for (i = 0; i < rdev->desc->n_voltages; i++) {
|
||||||
/* We only look for exact voltage matches here */
|
/* We only look for exact voltage matches here */
|
||||||
|
if (i < rdev->desc->linear_min_sel)
|
||||||
|
continue;
|
||||||
|
|
||||||
voltage = regulator_list_voltage(regulator, i);
|
voltage = regulator_list_voltage(regulator, i);
|
||||||
if (voltage < 0)
|
if (voltage < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct regulator_dev *rdev,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selector >= rdev->desc->n_voltages)
|
if (selector >= rdev->desc->n_voltages ||
|
||||||
|
selector < rdev->desc->linear_min_sel)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return rdev->desc->volt_table[selector];
|
return rdev->desc->volt_table[selector];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче