From: Dmitry Osipenko <digetx@gmail.com>
To: Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>
Cc: linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/3] regulator: core: Properly handle case where supply is the couple
Date: Mon, 19 Nov 2018 00:56:18 +0300 [thread overview]
Message-ID: <20181118215619.21518-4-digetx@gmail.com> (raw)
In-Reply-To: <20181118215619.21518-1-digetx@gmail.com>
Check whether supply regulator is the couple to avoid infinite recursion
during of locking.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
drivers/regulator/core.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c58e76a37e5f..a3ab419a3aa6 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -233,6 +233,21 @@ void regulator_unlock(struct regulator_dev *rdev)
mutex_unlock(®ulator_nesting_mutex);
}
+static bool regulator_supply_is_couple(struct regulator_dev *rdev)
+{
+ struct regulator_dev *c_rdev;
+ int i;
+
+ for (i = 1; i < rdev->coupling_desc.n_coupled; i++) {
+ c_rdev = rdev->coupling_desc.coupled_rdevs[i];
+
+ if (rdev->supply->rdev == c_rdev)
+ return true;
+ }
+
+ return false;
+}
+
static void regulator_unlock_recursive(struct regulator_dev *rdev,
unsigned int n_coupled)
{
@@ -245,7 +260,7 @@ static void regulator_unlock_recursive(struct regulator_dev *rdev,
if (!c_rdev)
continue;
- if (c_rdev->supply)
+ if (c_rdev->supply && !regulator_supply_is_couple(c_rdev))
regulator_unlock_recursive(
c_rdev->supply->rdev,
c_rdev->coupling_desc.n_coupled);
@@ -283,7 +298,7 @@ static int regulator_lock_recursive(struct regulator_dev *rdev,
*old_contended_rdev = NULL;
}
- if (c_rdev->supply) {
+ if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) {
err = regulator_lock_recursive(c_rdev->supply->rdev,
new_contended_rdev,
old_contended_rdev,
--
2.19.1
next prev parent reply other threads:[~2018-11-18 21:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-18 21:56 [PATCH v2 0/3] Coupled-regulators follow up Dmitry Osipenko
2018-11-18 21:56 ` [PATCH v2] dt-bindings: regulator: Change regulator-coupled-max-spread property Dmitry Osipenko
2018-11-18 21:56 ` [PATCH v2 1/3] regulator: core: Use ww_mutex for regulators locking Dmitry Osipenko
2018-11-18 21:56 ` Dmitry Osipenko [this message]
2018-11-18 21:56 ` [PATCH v2 3/3] regulator: core: Keep regulators-list locked while traversing the list Dmitry Osipenko
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=20181118215619.21518-4-digetx@gmail.com \
--to=digetx@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=robh+dt@kernel.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