[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1334280605.6755.1.camel@phoenix>
Date: Fri, 13 Apr 2012 09:30:05 +0800
From: Axel Lin <axel.lin@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Sangbeom Kim <sbkim73@...sung.com>, Liam Girdwood <lrg@...com>,
Mark Brown <broonie@...nsource.wolfsonmicro.com>
Subject: [PATCH] regulator: s5m8767: Use DIV_ROUND_UP to calculate selector
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@...il.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists