public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: core: Ensure simple linear voltage mappings falls within the specified range
@ 2012-05-14  2:33 Axel Lin
  2012-05-14  8:13 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2012-05-14  2:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mark Brown, Liam Girdwood

Integer division may truncate the result.
Use DIV_ROUND_UP to ensure simple linear voltage mappings falls within the
specified range.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5751f5e..8918271 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2047,7 +2047,7 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
 		return -EINVAL;
 	}
 
-	ret = (min_uV - rdev->desc->min_uV) / rdev->desc->uV_step;
+	ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
 	if (ret < 0)
 		return ret;
 
-- 
1.7.5.4




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-14  8:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14  2:33 [PATCH] regulator: core: Ensure simple linear voltage mappings falls within the specified range Axel Lin
2012-05-14  8:13 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox