mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Mark Brown <broonie@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/5] regulator: core: Resolve supply earlier
Date: Tue, 19 Apr 2016 11:16:59 +0100	[thread overview]
Message-ID: <5716059B.3080503@nvidia.com> (raw)
In-Reply-To: <20160411141621.GI3351@sirena.org.uk>


On 11/04/16 15:16, Mark Brown wrote:
> * PGP Signed by an unknown key
> 
> On Mon, Apr 11, 2016 at 04:11:01PM +0200, Thierry Reding wrote:
>> On Mon, Apr 11, 2016 at 03:03:00PM +0100, Mark Brown wrote:
> 
>>> This shouldn't be a hard dependency: most regulators won't be in bypass
>>> mode or otherwise depend on their parents enough to need this.
> 
>> I had initially proposed to resolve the supply only when necessary
>> during regulator_get_voltage() when checking for bypass, perhaps that
>> would after all be more appropriate here?
> 
> Yes, that had been what I'd expected.

So the following seems to work, but only item I am uncertain about
is if it is ok to move the mutex_lock to after the
machine_set_constraints()?

Jon

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 61d3918f329e..742d10371e2d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3126,8 +3126,13 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
 			return ret;
 		if (bypassed) {
 			/* if bypassed the regulator must have a supply */
-			if (!rdev->supply)
-				return -EINVAL;
+			if (!rdev->supply) {
+				ret = regulator_resolve_supply(rdev);
+				if (ret < 0)
+					return ret;
+				if (!rdev->supply)
+					return -EINVAL;
+			}
 
 			return _regulator_get_voltage(rdev->supply->rdev);
 		}
@@ -3939,8 +3944,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
 		rdev->dev.of_node = of_node_get(config->of_node);
 	}
 
-	mutex_lock(&regulator_list_mutex);
-
 	mutex_init(&rdev->mutex);
 	rdev->reg_data = config->driver_data;
 	rdev->owner = regulator_desc->owner;
@@ -3983,23 +3986,26 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	if (init_data)
 		constraints = &init_data->constraints;
 
+	if (init_data && init_data->supply_regulator)
+		rdev->supply_name = init_data->supply_regulator;
+	else if (regulator_desc->supply_name)
+		rdev->supply_name = regulator_desc->supply_name;
+
 	ret = set_machine_constraints(rdev, constraints);
 	if (ret < 0)
 		goto wash;
 
+	mutex_lock(&regulator_list_mutex);
+
 	ret = device_register(&rdev->dev);
 	if (ret != 0) {
 		put_device(&rdev->dev);
+		mutex_unlock(&regulator_list_mutex);
 		goto wash;
 	}
 
 	dev_set_drvdata(&rdev->dev, rdev);
 
-	if (init_data && init_data->supply_regulator)
-		rdev->supply_name = init_data->supply_regulator;
-	else if (regulator_desc->supply_name)
-		rdev->supply_name = regulator_desc->supply_name;
-
 	/* add consumers devices */
 	if (init_data) {
 		for (i = 0; i < init_data->num_consumer_supplies; i++) {
@@ -4009,6 +4015,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
 			if (ret < 0) {
 				dev_err(dev, "Failed to set supply %s\n",
 					init_data->consumer_supplies[i].supply);
+				mutex_unlock(&regulator_list_mutex);
 				goto unset_supplies;
 			}
 		}
@@ -4036,7 +4043,6 @@ wash:
 clean:
 	kfree(rdev);
 out:
-	mutex_unlock(&regulator_list_mutex);
 	kfree(config);
 	return ERR_PTR(ret);
 }

  reply	other threads:[~2016-04-19 10:17 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-07 14:22 Thierry Reding
2016-04-07 14:22 ` [PATCH 2/5] regulator: core: Use parent voltage from the supply when bypassed Thierry Reding
2016-04-12  6:31   ` Applied "regulator: core: Use parent voltage from the supply when bypassed" to the regulator tree Mark Brown
2016-04-07 14:22 ` [PATCH 3/5] regulator: helpers: Ensure bypass register field matches ON value Thierry Reding
2016-04-22 10:49   ` Applied "regulator: helpers: Ensure bypass register field matches ON value" to the regulator tree Mark Brown
2016-04-07 14:22 ` [PATCH 4/5] regulator: as3722: Add bypass support for LDO6 Thierry Reding
2016-04-11 16:15   ` Applied "regulator: as3722: Add bypass support for LDO6" to the regulator tree Mark Brown
2016-04-07 14:22 ` [PATCH 5/5] regulator: as3722: Constify regulator ops Thierry Reding
2016-04-11 16:15   ` Applied "regulator: as3722: Constify regulator ops" to the regulator tree Mark Brown
2016-04-11 10:59 ` [PATCH 1/5] regulator: core: Resolve supply earlier Jon Hunter
2016-04-11 11:46   ` Thierry Reding
2016-04-11 12:19     ` Jon Hunter
2016-04-11 12:49       ` Mark Brown
2016-04-11 14:03       ` Javier Martinez Canillas
2016-04-11 12:58     ` Mark Brown
2016-04-11 13:09       ` Thierry Reding
2016-04-11 13:45         ` Javier Martinez Canillas
2016-04-11 13:57           ` Mark Brown
2016-04-11 14:07             ` Thierry Reding
2016-04-11 14:32               ` Mark Brown
2016-04-11 14:49                 ` Thierry Reding
2016-04-11 15:50                   ` Mark Brown
2016-04-11 13:56         ` Mark Brown
2016-04-11 14:03 ` Mark Brown
2016-04-11 14:11   ` Thierry Reding
2016-04-11 14:16     ` Mark Brown
2016-04-19 10:16       ` Jon Hunter [this message]
2016-04-19 11:03         ` Thierry Reding
2016-04-19 15:40         ` Mark Brown
2016-04-19 16:09           ` Jon Hunter
2016-04-20 15:21             ` Mark Brown
2016-04-21 15:34               ` Jon Hunter

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=5716059B.3080503@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thierry.reding@gmail.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