From a56d66a2f01b172bc00d73b0b0392423c8aaae19 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 18 Jul 2013 22:21:57 +0800 Subject: [PATCH] regulator: core: Allow fixed voltage range in multiple linear ranges Current code does not allow fixed voltage range in multiple linear ranges. If someone does set range->uV_step == 0 in one of the linear ranges, we hit divided by zero bug. This patch fixes this issue. For fixed voltage range, return any selector means the same voltage. Thus just return 0. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e8604be4c66d..fd3f6e003729 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2436,9 +2436,15 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev, if (min_uV <= range->min_uV) min_uV = range->min_uV; - ret = DIV_ROUND_UP(min_uV - range->min_uV, range->uV_step); - if (ret < 0) - return ret; + /* range->uV_step == 0 means fixed voltage range */ + if (range->uV_step == 0) { + ret = 0; + } else { + ret = DIV_ROUND_UP(min_uV - range->min_uV, + range->uV_step); + if (ret < 0) + return ret; + } break; } -- 2.39.5