linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: s.hauer@pengutronix.de (Sascha Hauer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/6] regulator: core: introduce function to lock regulators and its supplies
Date: Wed, 30 Sep 2015 16:05:42 +0200	[thread overview]
Message-ID: <1443621946-8712-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1443621946-8712-1-git-send-email-s.hauer@pengutronix.de>

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 bd9db70..e5de3d9 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.5.3

  parent reply	other threads:[~2015-09-30 14:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 14:05 [RFC] regulator: Propagate voltage changes to supply regulators Sascha Hauer
2015-09-30 14:05 ` [PATCH 1/6] Revert "regulator: core: Handle full constraints systems when resolving supplies" Sascha Hauer
2015-09-30 18:03   ` Mark Brown
2015-09-30 14:05 ` Sascha Hauer [this message]
2015-09-30 14:21   ` [PATCH 2/6] regulator: core: introduce function to lock regulators and its supplies kbuild test robot
2015-09-30 14:05 ` [PATCH 3/6] regulator: core: create unlocked version of regulator_list_voltage Sascha Hauer
2015-09-30 22:36   ` Mark Brown
2015-10-01 11:29     ` Mark Brown
2015-09-30 14:05 ` [PATCH 4/6] regulator: core: Propagate voltage changes to supply regulators Sascha Hauer
2015-10-02 17:32   ` Mark Brown
2015-10-12 11:42     ` Sascha Hauer
2015-10-12 14:07       ` Mark Brown
2015-10-13  9:30         ` Sascha Hauer
2015-09-30 14:05 ` [PATCH 5/6] regulator: i.MX anatop: Allow supply regulator Sascha Hauer
2015-09-30 14:05 ` [PATCH 6/6] ARM: i.MX6 Phytec PFLA02: Add supplies for the SoC internal regulators Sascha Hauer
2015-10-02 17:33   ` 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=1443621946-8712-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).