public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] regulator: ad5398: Fix min/max current limit boundary checking
@ 2012-07-03  7:42 Axel Lin
  2012-07-03  7:54 ` Zhang, Sonic
  0 siblings, 1 reply; 12+ messages in thread
From: Axel Lin @ 2012-07-03  7:42 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Sonic Zhang, Lars-Peter Clausen, Liam Girdwood

It is ok to request current limit with min_uA < chip->min_uA and
max_uA > chip->max_uA.

We need to set min_uA = chip->min_uA if (min_uA < chip->min_uA),
this ensures the equation to calcuate selator does not return negative number.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
~
---
 drivers/regulator/ad5398.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index 46d05f3..84fdcda 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -89,9 +89,10 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
 	unsigned short data;
 	int ret;
 
-	if (min_uA > chip->max_uA || min_uA < chip->min_uA)
-		return -EINVAL;
-	if (max_uA > chip->max_uA || max_uA < chip->min_uA)
+	if (min_uA < chip->min_uA)
+		min_uA = chip->min_uA;
+
+	if (min_uA > chip->max_uA || max_uA < chip->min_uA)
 		return -EINVAL;
 
 	selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
-- 
1.7.9.5




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

end of thread, other threads:[~2012-07-04  3:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03  7:42 [PATCH v2] regulator: ad5398: Fix min/max current limit boundary checking Axel Lin
2012-07-03  7:54 ` Zhang, Sonic
2012-07-03  8:06   ` Lars-Peter Clausen
2012-07-03  8:13     ` Zhang, Sonic
2012-07-03  8:24       ` Lars-Peter Clausen
2012-07-03  8:33         ` Zhang, Sonic
2012-07-03  9:44           ` Axel Lin
2012-07-03  9:51             ` Zhang, Sonic
2012-07-03 11:36               ` Axel Lin
2012-07-04  2:56                 ` Zhang, Sonic
2012-07-04  3:18                   ` Axel Lin
2012-07-04  3:44                     ` Zhang, Sonic

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