regulator: gpio-regulator: Set the smallest voltage/current in the specified range
PATCH 1/1 regulator: gpio-regulator: Set the smallest voltage/current in the specified range
Do not assume the gpio regulator states map is sorted in any order. This patch ensures we always set the smallest voltage/current that falls within the specified range.
--- drivers/regulator/gpio-regulator.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/regulator/gpio-regulator.c +4 -4
@@ -105,15 +105,15 @@ static int gpio_regulator_set_value(struct regulator_dev *dev, int min, int max) {struct gpio_regulator_data *data =rdev_get_drvdata (dev); -int ptr, target, state; +int ptr, target, state, best_val =INT_MAX ; - target =-1 ;for (ptr =0 ; ptr < data->nr_states; ptr++) -if (data->states[ptr].value >= min && +if (data->states[ptr].value < best_val && + data->states[ptr].value >= min && data->states[ptr].value <= max) target = data->states[ptr].gpios; -if (target <0 ) +if (best_val ==INT_MAX )return -EINVAL ;for (ptr =0 ; ptr < data->nr_gpios; ptr++) {
Signature · 1 line
1.7.5.4
Am Donnerstag, 22. März 2012, 07:08:04 schrieb Axel Lin:
Quoted 5 lines
Do not assume the gpio regulator states map is sorted in any order. This patch ensures we always set the smallest voltage/current that falls within the specified range.
Signed-off-by Axel Lin <[email protected]>
nice addition, thanks
Quoted 28 lines
--- drivers/regulator/gpio-regulator.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/drivers/regulator/gpio-regulator.cindex 42e1cb1..b728b36 100644drivers/regulator/gpio-regulator.c +4
-4@@ -105,15 +105,15 @@ static int gpio_regulator_set_value(struct regulator_dev *dev, int min, int max) { struct gpio_regulator_data *data = rdev_get_drvdata(dev); -int ptr, target, state; +int ptr, target, state, best_val =INT_MAX ; - target =-1 ;for (ptr =0 ; ptr < data->nr_states; ptr++) -if (data->states[ptr].value >= min && +if (data->states[ptr].value < best_val && + data->states[ptr].value >= min && data->states[ptr].value <= max) target = data->states[ptr].gpios; -if (target <0 ) +if (best_val ==INT_MAX )return -EINVAL ;for (ptr =0 ; ptr < data->nr_gpios; ptr++) {
Mark Brown
AppliedQuoted 3 lines · Axel Lin
Do not assume the gpio regulator states map is sorted in any order. This patch ensures we always set the smallest voltage/current that falls within the specified range.
Applied, thanks.
Quoted 4 lines · Mark Brown <broonie <at> opensource.wolfsonmicro.com> writes:
Quoted 2 lines · Axel Lin
Do not assume the gpio regulator states map is sorted in any order. This patch ensures we always set the smallest voltage/current that falls
within
Quoted 4 lines
Quoted 1 line
the specified range.
Applied, thanks.
struct gpio_regulator_data *data = rdev_get_drvdata(dev);
- int ptr, target, state;
+ int ptr, target, state, best_val = INT_MAX;
- target = -1;
for (ptr = 0; ptr < data->nr_states; ptr++)
- if (data->states[ptr].value >= min &&
+ if (data->states[ptr].value < best_val &&
+ data->states[ptr].value >= min &&
data->states[ptr].value <= max)
target = data->states[ptr].gpios;
- if (target < 0)
+ if (best_val == INT_MAX)
Here seems something wrong, for best_val is always INT_MAX. From the discussion above, maybe best_val is should be reassigned in the for loop.
It may be like as the following:
- for (ptr = 0; ptr < data->nr_states; ptr++)
+ for (ptr = 0; ptr < data->nr_states; ptr++) {
if (data->states[ptr].value < best_val &&
data->states[ptr].value >= min &&
- data->states[ptr].value <= max)
+ data->states[ptr].value <= max) {
target = data->states[ptr].gpios;+ best_val = target;
+ }
What do you think? thanks;