* [PATCH] regulator: s5m8767: Use DIV_ROUND_UP to calculate selector
@ 2012-04-13 1:30 Axel Lin
2012-04-23 12:18 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2012-04-13 1:30 UTC (permalink / raw)
To: linux-kernel; +Cc: Sangbeom Kim, Liam Girdwood, Mark Brown
Integer division may truncate the result.
Use DIV_ROUND_UP to ensure new voltage setting falls within specified range.
Also properly handle the case min_vol < desc->min to ensure we don't return
negative value for selector.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/s5m8767.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index cb53187..ebe72d0 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -347,7 +347,10 @@ static int s5m8767_convert_voltage_to_sel(
if (max_vol < desc->min || min_vol > desc->max)
return -EINVAL;
- selector = (min_vol - desc->min) / desc->step;
+ if (min_vol < desc->min)
+ min_vol = desc->min;
+
+ selector = DIV_ROUND_UP(min_vol - desc->min, desc->step);
if (desc->min + desc->step * selector > max_vol)
return -EINVAL;
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] regulator: s5m8767: Use DIV_ROUND_UP to calculate selector
2012-04-13 1:30 [PATCH] regulator: s5m8767: Use DIV_ROUND_UP to calculate selector Axel Lin
@ 2012-04-23 12:18 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2012-04-23 12:18 UTC (permalink / raw)
To: Axel Lin; +Cc: linux-kernel, Sangbeom Kim, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 199 bytes --]
On Fri, Apr 13, 2012 at 09:30:05AM +0800, Axel Lin wrote:
> Integer division may truncate the result.
> Use DIV_ROUND_UP to ensure new voltage setting falls within 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-04-23 12:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-13 1:30 [PATCH] regulator: s5m8767: Use DIV_ROUND_UP to calculate selector Axel Lin
2012-04-23 12:18 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox