Skip to contentSkip to conversation

regulator: A few fixes for supply resolution

PATCH In review Jon Hunter 2 participants 14 messages Apr 21, 2016 – Apr 25, 2016

Subsystems (2)
lore
Share & tools
lore

Jon Hunter

author maintainer
#0 lore raw

cover regulator: A few fixes for supply resolution

This series is to mainly address the boot failures reported on the Tegra124 Jetson TK1 where the AS3772 PMIC is failing to probe on -next [0]. However, there are a couple other patches I am including here which came from looking at this problem. Here is a summary of the patches ...

Patch 1: Allows additional supplies to be resolved even if one fails Patch 2: Fixes potential crash if turning on a supply fails Patch 3-5: Address issue with AS3722 probe failing

[0] http://marc.info/?l=linux-tegra&m=145927821311669&w=2

Jon Hunter (5):
regulator: core: Don't terminate supply resolution early
regulator: core: Clear the supply pointer if enabling fails
regulator: core: Move registration of regulator device
regulator: core: Add early supply resolution for a bypassed regulator
regulator: helpers: Ensure bypass register field matches ON value

 drivers/regulator/core.c    | 59 ++++++++++++++++++++++++++-------------------
 drivers/regulator/helpers.c |  2 +-
 2 files changed, 35 insertions(+), 26 deletions(-)
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

PATCH 1/5 regulator: core: Don't terminate supply resolution early

The function regulator_register_resolve_supply() is called from the context of class_for_each_dev() (during the regulator registration) to resolve any supplies added. regulator_register_resolve_supply() will return an error if a regulator's supply cannot be resolved and this will terminate the loop in class_for_each_dev(). This means that we will not attempt to resolve any other supplies after one has failed. Hence, this may delay the resolution of other regulator supplies until the failing one itself can be resolved.

Rather than terminating the loop early, don't return an error code and keep attempting to resolve any other supplies for regulators that have been registered.

---
 drivers/regulator/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/regulator/core.c +6 -1
index 61d3918f329e..a0b52ef11c30 100644
@@ -3865,7 +3865,12 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
 
 static int regulator_register_resolve_supply(struct device *dev, void *data)
 {
-	return regulator_resolve_supply(dev_to_rdev(dev));
+	struct regulator_dev *rdev = dev_to_rdev(dev);
+
+	if (regulator_resolve_supply(rdev))
+		rdev_dbg(rdev, "unable to resolve supply\n");
+
+	return 0;
 }
 
 /**
Signature · 1 line
2.1.4
maintainer
#2 lore raw

Applied "regulator: core: Don't terminate supply resolution early" to the regulator tree

The patch

regulator: core: Don't terminate supply resolution early

has been applied to the regulator tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From 7ddede6a58a0bd26efcfd2a5055611195411f514 Mon Sep 17 00:00:00 2001
From: Jon Hunter <[email protected]>
Date: Thu, 21 Apr 2016 17:11:57 +0100
Subject: [PATCH] regulator: core: Don't terminate supply resolution early

The function regulator_register_resolve_supply() is called from the context of class_for_each_dev() (during the regulator registration) to resolve any supplies added. regulator_register_resolve_supply() will return an error if a regulator's supply cannot be resolved and this will terminate the loop in class_for_each_dev(). This means that we will not attempt to resolve any other supplies after one has failed. Hence, this may delay the resolution of other regulator supplies until the failing one itself can be resolved.

Rather than terminating the loop early, don't return an error code and keep attempting to resolve any other supplies for regulators that have been registered.

---
 drivers/regulator/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/regulator/core.c +6 -1
index fd0e4e37f4e1..9922922ce6bd 100644
@@ -3842,7 +3842,12 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
 
 static int regulator_register_resolve_supply(struct device *dev, void *data)
 {
-	return regulator_resolve_supply(dev_to_rdev(dev));
+	struct regulator_dev *rdev = dev_to_rdev(dev);
+
+	if (regulator_resolve_supply(rdev))
+		rdev_dbg(rdev, "unable to resolve supply\n");
+
+	return 0;
 }
 
 /**
Signature · 1 line
2.8.0.rc3
author maintainer
#3 lore raw

PATCH 2/5 regulator: core: Clear the supply pointer if enabling fails

In reply to Jon Hunter

During the resolution of a regulator's supply, we may attempt to enable the supply if the regulator itself is already enabled. If enabling the supply fails, then we will call _regulator_put() for the supply. However, the pointer to the supply has not been cleared for the regulator and this will cause a crash if we then unregister the regulator and attempt to call regulator_put() a second time for the supply. Fix this by clearing the supply pointer if enabling the supply after fails when resolving the supply for a regulator.

---
 drivers/regulator/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/regulator/core.c +1 -0
index a0b52ef11c30..39d05fcc07e9 100644
@@ -1545,6 +1545,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 		ret = regulator_enable(rdev->supply);
 		if (ret < 0) {
 			_regulator_put(rdev->supply);
+			rdev->supply = NULL;
 			return ret;
 		}
 	}
Signature · 1 line
2.1.4
maintainer
#4 lore raw

Applied "regulator: core: Clear the supply pointer if enabling fails" to the regulator tree

The patch

regulator: core: Clear the supply pointer if enabling fails

has been applied to the regulator tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From 8e5356a73604f53da6a1e0756727cb8f9f7bba17 Mon Sep 17 00:00:00 2001
From: Jon Hunter <[email protected]>
Date: Thu, 21 Apr 2016 17:11:58 +0100
Subject: [PATCH] regulator: core: Clear the supply pointer if enabling fails

During the resolution of a regulator's supply, we may attempt to enable the supply if the regulator itself is already enabled. If enabling the supply fails, then we will call _regulator_put() for the supply. However, the pointer to the supply has not been cleared for the regulator and this will cause a crash if we then unregister the regulator and attempt to call regulator_put() a second time for the supply. Fix this by clearing the supply pointer if enabling the supply after fails when resolving the supply for a regulator.

---
 drivers/regulator/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/regulator/core.c +1 -0
index 9922922ce6bd..bd9ec309b707 100644
@@ -1536,6 +1536,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 		ret = regulator_enable(rdev->supply);
 		if (ret < 0) {
 			_regulator_put(rdev->supply);
+			rdev->supply = NULL;
 			return ret;
 		}
 	}
Signature · 1 line
2.8.0.rc3
author maintainer
#5 lore raw

PATCH 3/5 regulator: core: Move registration of regulator device

In reply to Jon Hunter

The public functions to acquire a regulator, such as regulator_get(), internally look-up the regulator from the list of regulators that have been registered with the regulator device class. The registration of a new regulator with the regulator device class happens before the regulator has been completely setup. Therefore, it is possible that the regulator could be acquired before it has been setup successfully. To avoid this move the device registration of the regulator to the end of the regulator setup and update the error exit path accordingly.

---
 drivers/regulator/core.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/regulator/core.c +9 -15
index 39d05fcc07e9..754f3b4c2218 100644
@@ -3993,14 +3993,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	if (ret < 0)
 		goto wash;
 
-	ret = device_register(&rdev->dev);
-	if (ret != 0) {
-		put_device(&rdev->dev);
-		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)
@@ -4020,9 +4012,17 @@ regulator_register(const struct regulator_desc *regulator_desc,
 		}
 	}
 
-	rdev_init_debugfs(rdev);
 	mutex_unlock(&regulator_list_mutex);
 
+	ret = device_register(&rdev->dev);
+	if (ret != 0) {
+		put_device(&rdev->dev);
+		goto unset_supplies;
+	}
+
+	dev_set_drvdata(&rdev->dev, rdev);
+	rdev_init_debugfs(rdev);
+
 	/* try to resolve regulators supply since a new one was registered */
 	class_for_each_device(&regulator_class, NULL, NULL,
 			      regulator_register_resolve_supply);
@@ -4031,17 +4031,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
 unset_supplies:
 	unset_regulator_supplies(rdev);
-	regulator_ena_gpio_free(rdev);
-	device_unregister(&rdev->dev);
-	/* device core frees rdev */
-	goto out;
-
 wash:
 	kfree(rdev->constraints);
 	regulator_ena_gpio_free(rdev);
 clean:
 	kfree(rdev);
-out:
 	mutex_unlock(&regulator_list_mutex);
 	kfree(config);
 	return ERR_PTR(ret);
Signature · 1 line
2.1.4
maintainer
#6 lore raw

Applied "regulator: core: Move registration of regulator device" to the regulator tree

The patch

regulator: core: Move registration of regulator device

has been applied to the regulator tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From c438b9d017362b65f6b1a9e54f7f35e7f873dc7c Mon Sep 17 00:00:00 2001
From: Jon Hunter <[email protected]>
Date: Thu, 21 Apr 2016 17:11:59 +0100
Subject: [PATCH] regulator: core: Move registration of regulator device

The public functions to acquire a regulator, such as regulator_get(), internally look-up the regulator from the list of regulators that have been registered with the regulator device class. The registration of a new regulator with the regulator device class happens before the regulator has been completely setup. Therefore, it is possible that the regulator could be acquired before it has been setup successfully. To avoid this move the device registration of the regulator to the end of the regulator setup and update the error exit path accordingly.

---
 drivers/regulator/core.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/regulator/core.c +9 -15
index a17ce6cbbe77..8362a0a5105d 100644
@@ -3970,14 +3970,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	if (ret < 0)
 		goto wash;
 
-	ret = device_register(&rdev->dev);
-	if (ret != 0) {
-		put_device(&rdev->dev);
-		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)
@@ -3997,9 +3989,17 @@ regulator_register(const struct regulator_desc *regulator_desc,
 		}
 	}
 
-	rdev_init_debugfs(rdev);
 	mutex_unlock(&regulator_list_mutex);
 
+	ret = device_register(&rdev->dev);
+	if (ret != 0) {
+		put_device(&rdev->dev);
+		goto unset_supplies;
+	}
+
+	dev_set_drvdata(&rdev->dev, rdev);
+	rdev_init_debugfs(rdev);
+
 	/* try to resolve regulators supply since a new one was registered */
 	class_for_each_device(&regulator_class, NULL, NULL,
 			      regulator_register_resolve_supply);
@@ -4008,17 +4008,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
 unset_supplies:
 	unset_regulator_supplies(rdev);
-	regulator_ena_gpio_free(rdev);
-	device_unregister(&rdev->dev);
-	/* device core frees rdev */
-	goto out;
-
 wash:
 	kfree(rdev->constraints);
 	regulator_ena_gpio_free(rdev);
 clean:
 	kfree(rdev);
-out:
 	mutex_unlock(&regulator_list_mutex);
 	kfree(config);
 	return ERR_PTR(ret);
Signature · 1 line
2.8.0.rc3
author maintainer
#7 lore raw

PATCH 4/5 regulator: core: Add early supply resolution for a bypassed regulator

In reply to Jon Hunter

The call to set_machine_constraints() in regulator_register(), will attempt to get the voltage for the regulator.

A regulator that is in bypass will fail to be registered because we will attempt to get the voltage of the regulator (ie. it's bypass voltage) before the supply for the regulator has been resolved. Therefore, when getting the voltage for a bypassed regulator, if the supply has not been resolved, then attempt to resolve it. Additionally, move the setup of the regulator's supply name to before the call to set_machine_constraints() so that it can be resolved.

Please note that regulator_resolve_supply() will call regulator_dev_lookup() which may acquire the regulator_list_mutex. To avoid any deadlocks we cannot hold the regulator_list_mutex when calling regulator_resolve_supply(). Following this change because set_machine_constraints() may now result in a call to regulator_resolve_supply() for a bypassed regulator, we can no longer hold the regulator_list_mutex around this call. To avoid this rather than holding the lock around a large portion of the registration code, just hold the lock when aquiring any GPIOs and setting up supplies because these sections may add entries to the regulator_map_list and regulator_ena_gpio_list, respectively.

---
 drivers/regulator/core.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/regulator/core.c +20 -11
index 754f3b4c2218..4f57a1832079 100644
@@ -3127,8 +3127,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);
 		}
@@ -3945,8 +3950,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;
@@ -3971,7 +3974,9 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
 	if ((config->ena_gpio || config->ena_gpio_initialized) &&
 	    gpio_is_valid(config->ena_gpio)) {
+		mutex_lock(&regulator_list_mutex);
 		ret = regulator_ena_gpio_request(rdev, config);
+		mutex_unlock(&regulator_list_mutex);
 		if (ret != 0) {
 			rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
 				 config->ena_gpio, ret);
@@ -3989,31 +3994,32 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	if (init_data)
 		constraints = &init_data->constraints;
 
-	ret = set_machine_constraints(rdev, constraints);
-	if (ret < 0)
-		goto wash;
-
 	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;
+
 	/* add consumers devices */
 	if (init_data) {
+		mutex_lock(&regulator_list_mutex);
 		for (i = 0; i < init_data->num_consumer_supplies; i++) {
 			ret = set_consumer_device_supply(rdev,
 				init_data->consumer_supplies[i].dev_name,
 				init_data->consumer_supplies[i].supply);
 			if (ret < 0) {
+				mutex_unlock(&regulator_list_mutex);
 				dev_err(dev, "Failed to set supply %s\n",
 					init_data->consumer_supplies[i].supply);
 				goto unset_supplies;
 			}
 		}
+		mutex_unlock(&regulator_list_mutex);
 	}
 
-	mutex_unlock(&regulator_list_mutex);
-
 	ret = device_register(&rdev->dev);
 	if (ret != 0) {
 		put_device(&rdev->dev);
@@ -4030,13 +4036,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	return rdev;
 
 unset_supplies:
+	mutex_lock(&regulator_list_mutex);
 	unset_regulator_supplies(rdev);
+	mutex_unlock(&regulator_list_mutex);
 wash:
 	kfree(rdev->constraints);
+	mutex_lock(&regulator_list_mutex);
 	regulator_ena_gpio_free(rdev);
+	mutex_unlock(&regulator_list_mutex);
 clean:
 	kfree(rdev);
-	mutex_unlock(&regulator_list_mutex);
 	kfree(config);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.1.4
maintainer
#8 lore raw

Re: [PATCH 4/5] regulator: core: Add early supply resolution for a bypassed regulator

Quoted 7 lines · Jon Hunter

A regulator that is in bypass will fail to be registered because we will attempt to get the voltage of the regulator (ie. it's bypass voltage) before the supply for the regulator has been resolved. Therefore, when getting the voltage for a bypassed regulator, if the supply has not been resolved, then attempt to resolve it. Additionally, move the setup of the regulator's supply name to before the call to set_machine_constraints() so that it can be resolved.

The basic pattern here makes sense but rather than doing this specifically in the case where we have a bypassed supply we didn't resolve yet I think we should instead always try to resolve the supply but ignore the error unless we actively need the supply. I'd be surprised if we didn't run into other cases where we need to do this so it seems better to try the resolution in one place.

author maintainer
#9 lore raw

Re: [PATCH 4/5] regulator: core: Add early supply resolution for a bypassed regulator

Quoted 12 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 7 lines · Jon Hunter

A regulator that is in bypass will fail to be registered because we will attempt to get the voltage of the regulator (ie. it's bypass voltage) before the supply for the regulator has been resolved. Therefore, when getting the voltage for a bypassed regulator, if the supply has not been resolved, then attempt to resolve it. Additionally, move the setup of the regulator's supply name to before the call to set_machine_constraints() so that it can be resolved.

Quoted 6 lines

The basic pattern here makes sense but rather than doing this specifically in the case where we have a bypassed supply we didn't resolve yet I think we should instead always try to resolve the supply but ignore the error unless we actively need the supply. I'd be surprised if we didn't run into other cases where we need to do this so it seems better to try the resolution in one place.

OK. Sorry if I have misunderstood you here, but this sounds more like Thierry's initial proposal [0] but ignoring the any errors returned (and we need to fix-up the locking in this patch). In the discussion that followed I thought we agreed to only do this for the bypass case [1]. As far as I am concerned either will work, but to confirm we should just always try to resolve the supply early during regulator_register(), correct?

Cheers
Jon

[0] http://marc.info/?t=146003907800001&r=1&w=2
[1] http://marc.info/?l=linux-kernel&m=146038421710211&w=2

maintainer
#10 lore raw

Re: [PATCH 4/5] regulator: core: Add early supply resolution for a bypassed regulator

Quoted 3 lines · Jon Hunter

OK. Sorry if I have misunderstood you here, but this sounds more like Thierry's initial proposal [0] but ignoring the any errors returned (and we need to fix-up the locking in this patch). In the discussion that

Yes!

Quoted 3 lines

followed I thought we agreed to only do this for the bypass case [1]. As far as I am concerned either will work, but to confirm we should just always try to resolve the supply early during regulator_register(), correct?

We need to only *fail* in the bypass case.

author maintainer
#11 lore raw

Re: [PATCH 4/5] regulator: core: Add early supply resolution for a bypassed regulator

Quoted 8 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 3 lines · Jon Hunter

OK. Sorry if I have misunderstood you here, but this sounds more like Thierry's initial proposal [0] but ignoring the any errors returned (and we need to fix-up the locking in this patch). In the discussion that

Quoted 7 lines

Yes!

Quoted 3 lines

followed I thought we agreed to only do this for the bypass case [1]. As far as I am concerned either will work, but to confirm we should just always try to resolve the supply early during regulator_register(), correct?

We need to only *fail* in the bypass case.

OK. So this is what I have now. Is it weird to return EPROBE_DEFER in _regulator_get_voltage()? If so, I could add a test for bypass in the regulator_register().

drivers/regulator/core.c +22 -10
index 5b46d907e61d..7a6b7f667bcb 100644
@@ -3126,7 +3126,7 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
 		if (bypassed) {
 			/* if bypassed the regulator must have a supply */
 			if (!rdev->supply)
-				return -EINVAL;
+				return -EPROBE_DEFER;
 
 			return _regulator_get_voltage(rdev->supply->rdev);
 		}
@@ -3943,8 +3943,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;
@@ -3969,7 +3967,9 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
 	if ((config->ena_gpio || config->ena_gpio_initialized) &&
 	    gpio_is_valid(config->ena_gpio)) {
+		mutex_lock(&regulator_list_mutex);
 		ret = regulator_ena_gpio_request(rdev, config);
+		mutex_unlock(&regulator_list_mutex);
 		if (ret != 0) {
 			rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
 				 config->ena_gpio, ret);
@@ -3987,31 +3987,40 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	if (init_data)
 		constraints = &init_data->constraints;
 
-	ret = set_machine_constraints(rdev, constraints);
-	if (ret < 0)
-		goto wash;
-
 	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;
 
+	/*
+	 * Attempt to resolve the regulator supply, if specified,
+	 * but don't return an error if we fail because we will try
+	 * to resolve it again later as more regulators are added.
+	 */
+	if (regulator_resolve_supply(rdev))
+		rdev_dbg(rdev, "unable to resolve supply\n");
+
+	ret = set_machine_constraints(rdev, constraints);
+	if (ret < 0)
+		goto wash;
+
 	/* add consumers devices */
 	if (init_data) {
+		mutex_lock(&regulator_list_mutex);
 		for (i = 0; i < init_data->num_consumer_supplies; i++) {
 			ret = set_consumer_device_supply(rdev,
 				init_data->consumer_supplies[i].dev_name,
 				init_data->consumer_supplies[i].supply);
 			if (ret < 0) {
+				mutex_unlock(&regulator_list_mutex);
 				dev_err(dev, "Failed to set supply %s\n",
 					init_data->consumer_supplies[i].supply);
 				goto unset_supplies;
 			}
 		}
+		mutex_unlock(&regulator_list_mutex);
 	}
 
-	mutex_unlock(&regulator_list_mutex);
-
 	ret = device_register(&rdev->dev);
 	if (ret != 0) {
 		put_device(&rdev->dev);
@@ -4028,13 +4037,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	return rdev;
 
 unset_supplies:
+	mutex_lock(&regulator_list_mutex);
 	unset_regulator_supplies(rdev);
+	mutex_unlock(&regulator_list_mutex);
 wash:
 	kfree(rdev->constraints);
+	mutex_lock(&regulator_list_mutex);
 	regulator_ena_gpio_free(rdev);
+	mutex_unlock(&regulator_list_mutex);
 clean:
 	kfree(rdev);
-	mutex_unlock(&regulator_list_mutex);
 	kfree(config);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.1.4
maintainer
#12 lore raw

Re: [PATCH 4/5] regulator: core: Add early supply resolution for a bypassed regulator

Quoted 7 lines · Jon Hunter
Quoted 1 line · Mark Brown

We need to only *fail* in the bypass case.

OK. So this is what I have now. Is it weird to return EPROBE_DEFER in _regulator_get_voltage()? If so, I could add a test for bypass in the regulator_register().

It should be fine but perhaps print an error saying that it's a bypassed regulator with no supply? Deferring for no explicit reason can be confusing.

author maintainer
#13 lore raw

PATCH 5/5 regulator: helpers: Ensure bypass register field matches ON value

In reply to Jon Hunter

When checking bypass state for a regulator, we check to see if any bits in the bypass mask are set. For most cases this is fine because there is typically, only a single bit used to determine if the regulator is in bypass. However, for some regulators, such as LDO6 on AS3722, the bypass state is indicate by a value rather than a single bit. Therefore, when checking the bypass state, check that the bypass field matches the ON value.

---
 drivers/regulator/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/helpers.c +1 -1
index b1e32e7482e9..bcf38fd5106a 100644
@@ -460,7 +460,7 @@ int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
 	if (ret != 0)
 		return ret;
 
-	*enable = val & rdev->desc->bypass_mask;
+	*enable = (val & rdev->desc->bypass_mask) == rdev->desc->bypass_val_on;
 
 	return 0;
 }
Signature · 1 line
2.1.4