Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1245577

[PATCH 4/8] regulator: core: introduce function to lock regulators and its supplies

From Sascha Hauer <s.hauer@pengutronix.de>
Newsgroups linux.kernel
Subject [PATCH 4/8] regulator: core: introduce function to lock regulators and its supplies
Date 2015-10-13 12:50 +0200
Message-ID <qj5jB-45m-33@gated-at.bofh.it> (permalink)
References <qj5jz-45m-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Each regulator_dev is locked with its own mutex. This is fine as long
as only one regulator_dev is locked, but makes lockdep unhappy when we
have to walk up the supply chain like it can happen in
regulator_get_voltage:

regulator_get_voltage ->
 mutex_lock(&regulator->rdev->mutex) ->
_regulator_get_voltage(regulator->rdev) ->
regulator_get_voltage(rdev->supply) ->
mutex_lock(&regulator->rdev->mutex);

This causes lockdep to issue a possible deadlock warning.

There are at least two ways to work around this:

- We can always lock the whole supply chain using the functions
  introduced with this patch.
- We could store the current voltage in struct regulator_rdev so
  that we do not have to walk up the supply chain for the
  _regulator_get_voltage case.

Anyway, regulator_lock_supply/regulator_unlock_supply will be needed
once we allow regulator_set_voltage to optimize the supply voltages.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b814451..bd66097 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -132,6 +132,45 @@ static bool have_full_constraints(void)
 }
 
 /**
+ * regulator_lock_supply - lock a regulator and its supplies
+ * @rdev:         regulator source
+ */
+static void regulator_lock_supply(struct regulator_dev *rdev)
+{
+	struct regulator *supply;
+	int i = 0;
+
+	while (1) {
+		mutex_lock_nested(&rdev->mutex, i++);
+		supply = rdev->supply;
+
+		if (!rdev->supply)
+			return;
+
+		rdev = supply->rdev;
+	}
+}
+
+/**
+ * regulator_unlock_supply - unlock a regulator and its supplies
+ * @rdev:         regulator source
+ */
+static void regulator_unlock_supply(struct regulator_dev *rdev)
+{
+	struct regulator *supply;
+
+	while (1) {
+		mutex_unlock(&rdev->mutex);
+		supply = rdev->supply;
+
+		if (!rdev->supply)
+			return;
+
+		rdev = supply->rdev;
+	}
+}
+
+/**
  * of_get_regulator - get a regulator device node based on supply name
  * @dev: Device pointer for the consumer (of regulator) device
  * @supply: regulator supply name
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] regulator: Propagate voltage changes to supply regulators Sascha Hauer <s.hauer@pengutronix.de> - 2015-10-13 12:50 +0200
  [PATCH 4/8] regulator: core: introduce function to lock regulators and its supplies Sascha Hauer <s.hauer@pengutronix.de> - 2015-10-13 12:50 +0200
  [PATCH 3/8] regulator: introduce min_dropout_uv Sascha Hauer <s.hauer@pengutronix.de> - 2015-10-13 12:50 +0200
    Re: [PATCH 3/8] regulator: introduce min_dropout_uv Mark Brown <broonie@kernel.org> - 2015-10-16 18:20 +0200
    Applied "regulator: introduce min_dropout_uv" to the regulator tree Mark Brown <broonie@kernel.org> - 2015-10-16 18:50 +0200
      Re: Applied "regulator: introduce min_dropout_uv" to the regulator  tree Mark Brown <broonie@kernel.org> - 2015-10-16 19:00 +0200
  [PATCH 6/8] regulator: core: Propagate voltage changes to supply regulators Sascha Hauer <s.hauer@pengutronix.de> - 2015-10-13 12:50 +0200
    Re: [PATCH 6/8] regulator: core: Propagate voltage changes to supply  regulators Mark Brown <broonie@kernel.org> - 2015-10-16 19:00 +0200

csiph-web