* [PATCH RFC/RFT] regulator: da9052: Ensure the selected voltage falls within the specified range
@ 2012-03-05 12:27 Axel Lin
2012-03-05 12:43 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2012-03-05 12:27 UTC (permalink / raw)
To: linux-kernel
Cc: David Dajun Chen, Ashish Jangam, Ying-Chun Liu (PaulLiu),
Mark Brown, Liam Girdwood
Integer division may truncate the result, use DIV_ROUND_UP to ensure the
selected voltage falls within the specified range.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/da9052-regulator.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 0689ad4..5e8813f 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -226,7 +226,7 @@ static int da9052_regulator_set_voltage_int(struct regulator_dev *rdev,
if (min_uV < info->min_uV)
min_uV = info->min_uV;
- *selector = (min_uV - info->min_uV) / info->step_uV;
+ *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
ret = da9052_list_voltage(rdev, *selector);
if (ret < 0)
@@ -318,10 +318,10 @@ static int da9052_set_buckperi_voltage(struct regulator_dev *rdev, int min_uV,
if ((regulator->da9052->chip_id == DA9052) &&
(min_uV >= DA9052_CONST_3uV))
*selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV +
- ((min_uV - DA9052_CONST_3uV) /
- (DA9052_BUCK_PERI_3uV_STEP));
+ DIV_ROUND_UP(min_uV - DA9052_CONST_3uV,
+ DA9052_BUCK_PERI_3uV_STEP);
else
- *selector = (min_uV - info->min_uV) / info->step_uV;
+ *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
ret = da9052_list_buckperi_voltage(rdev, *selector);
if (ret < 0)
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RFC/RFT] regulator: da9052: Ensure the selected voltage falls within the specified range
2012-03-05 12:27 [PATCH RFC/RFT] regulator: da9052: Ensure the selected voltage falls within the specified range Axel Lin
@ 2012-03-05 12:43 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2012-03-05 12:43 UTC (permalink / raw)
To: Axel Lin
Cc: linux-kernel, David Dajun Chen, Ashish Jangam,
Ying-Chun Liu (PaulLiu), Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 204 bytes --]
On Mon, Mar 05, 2012 at 08:27:56PM +0800, Axel Lin wrote:
> Integer division may truncate the result, use DIV_ROUND_UP to ensure the
> selected voltage falls within the specified range.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-03-05 12:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-05 12:27 [PATCH RFC/RFT] regulator: da9052: Ensure the selected voltage falls within the specified range Axel Lin
2012-03-05 12:43 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox