mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Liam Girdwood <lrg@ti.com>
Cc: linux-kernel@vger.kernel.org, Axel Lin <axel.lin@gmail.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 2/2] regulator: core: Check that the selector from map_voltage() is valid
Date: Tue, 26 Jun 2012 11:26:22 +0100	[thread overview]
Message-ID: <1340706382-27297-2-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1340706382-27297-1-git-send-email-broonie@opensource.wolfsonmicro.com>

Lots of regulator drivers have checks in their map_voltage() functions
to verify that the result of the mapping is in the range originally
specified. Factor these out in the core and provide a bit of extra
defensiveness for other drivers by doing the check in the core.

Since we're now doing a list_voltage() earlier move the current mapping
back to a voltage out into the set_voltage() call to save redoing it.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/regulator/core.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9f28f2f..0ba27c2 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2071,7 +2071,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 {
 	int ret;
 	int delay = 0;
-	int best_val;
+	int best_val = 0;
 	unsigned int selector;
 	int old_selector = -1;
 
@@ -2095,6 +2095,15 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 	if (rdev->desc->ops->set_voltage) {
 		ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
 						   &selector);
+
+		if (ret >= 0) {
+			if (rdev->desc->ops->list_voltage)
+				best_val = rdev->desc->ops->list_voltage(rdev,
+									 selector);
+			else
+				best_val = _regulator_get_voltage(rdev);
+		}
+
 	} else if (rdev->desc->ops->set_voltage_sel) {
 		if (rdev->desc->ops->map_voltage) {
 			ret = rdev->desc->ops->map_voltage(rdev, min_uV,
@@ -2110,10 +2119,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 		}
 
 		if (ret >= 0) {
-			if (min_uV < rdev->desc->ops->list_voltage(rdev,
-								   ret) &&
-			    max_uV > rdev->desc->ops->list_voltage(rdev,
-								   ret)) {
+			best_val = rdev->desc->ops->list_voltage(rdev, ret);
+			if (min_uV <= best_val && max_uV >= best_val) {
 				selector = ret;
 				ret = rdev->desc->ops->set_voltage_sel(rdev,
 								       ret);
@@ -2125,11 +2132,6 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 		ret = -EINVAL;
 	}
 
-	if (rdev->desc->ops->list_voltage)
-		best_val = rdev->desc->ops->list_voltage(rdev, selector);
-	else
-		best_val = _regulator_get_voltage(rdev);
-
 	/* Call set_voltage_time_sel if successfully obtained old_selector */
 	if (ret == 0 &&
 	    _regulator_is_enabled(rdev) && ret == 0 && old_selector >= 0 &&
-- 
1.7.10


  reply	other threads:[~2012-06-26 10:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-26 10:26 [PATCH 1/2] regulator: core: Only delay if we successfully set the voltage Mark Brown
2012-06-26 10:26 ` Mark Brown [this message]
2012-06-26 12:40   ` [PATCH 2/2] regulator: core: Check that the selector from map_voltage() is valid Axel Lin
2012-06-26 13:13     ` Mark Brown
2012-06-26 10:30 ` [PATCH 1/2] regulator: core: Only delay if we successfully set the voltage Axel Lin
2012-06-26 10:40   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340706382-27297-2-git-send-email-broonie@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=axel.lin@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome