From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: David Collins <collinsd@codeaurora.org>
Cc: Liam Girdwood <lrg@slimlogic.co.uk>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Deadlock scenario in regulator core
Date: Tue, 22 Mar 2011 22:31:57 +0000 [thread overview]
Message-ID: <20110322223156.GA10782@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <4D891C59.1030009@codeaurora.org>
On Tue, Mar 22, 2011 at 03:02:01PM -0700, David Collins wrote:
> The locks for S1 and L2 are taken in opposite orders in the two threads;
> therefore, it is possible to achieve deadlock. I am not sure about the
> best way to resolve this situation. Is there a correctness requirement
> that regulator_enable holds the child regulator's lock when it attempts to
> enable the parent regulator? Likewise, is the lock around
> _notifier_call_chain required?
No need to hold the child lock, when we take the reference on the supply
we own the reference. It's just that the systems which need to use
daisychained regulators (mostly a DCDC to power LDOs for better
efficiency) are moderately rare and tend to not bother representing the
supply relationship as the parent regulator tends to be always on.
In fact it looks rather like the refcounting for supplies is wrong
anyway, regulator_disable() unconditionally drops references to supplies
but regulator_enable() only enables them if the refcount was previously
zero, and it appears we don't clean up supplies after failed enables.
The below patch (which I've not even compile tested) should resolve both
issues, could you give it a spin and let me know if it works for you
please?
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 3ffc697..0a7fbde 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1284,19 +1284,6 @@ static int _regulator_enable(struct regulator_dev *rdev)
{
int ret, delay;
- if (rdev->use_count == 0) {
- /* do we need to enable the supply regulator first */
- if (rdev->supply) {
- mutex_lock(&rdev->supply->mutex);
- ret = _regulator_enable(rdev->supply);
- mutex_unlock(&rdev->supply->mutex);
- if (ret < 0) {
- rdev_err(rdev, "failed to enable: %d\n", ret);
- return ret;
- }
- }
- }
-
/* check voltage and requested load before enabling */
if (rdev->constraints &&
(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
@@ -1370,10 +1357,27 @@ int regulator_enable(struct regulator *regulator)
{
struct regulator_dev *rdev = regulator->rdev;
int ret = 0;
+ int disret;
+
+ if (rdev->supply) {
+ ret = regulator_enable(rdev->supply);
+ if (ret < 0) {
+ rdev_err(rdev, "failed to enable supply: %d\n", ret);
+ return ret;
+ }
+ }
mutex_lock(&rdev->mutex);
ret = _regulator_enable(rdev);
mutex_unlock(&rdev->mutex);
+
+ if (ret != 0 && rdev->supply) {
+ disret = regulator_disable(rdev->supply);
+ if (disret < 0)
+ rdev_err(rdev, "failed to disable supply: %d\n",
+ disret);
+ }
+
return ret;
}
EXPORT_SYMBOL_GPL(regulator_enable);
next prev parent reply other threads:[~2011-03-22 22:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-22 22:02 Deadlock scenario in regulator core David Collins
2011-03-22 22:31 ` Mark Brown [this message]
2011-03-22 23:30 ` David Collins
2011-03-22 23:45 ` Mark Brown
2011-03-22 22:37 ` Steven Rostedt
2011-03-22 23:08 ` David Collins
2011-03-22 23:19 ` Steven Rostedt
2011-03-22 23:41 ` David Collins
2011-03-23 0:07 ` Steven Rostedt
2011-03-23 0:11 ` Mark Brown
2011-03-25 10:55 ` Peter Zijlstra
2011-03-23 0:01 ` Mark Brown
2011-03-23 0:38 ` Steven Rostedt
2011-03-23 10:42 ` Mark Brown
2011-03-25 10:59 ` Peter Zijlstra
2011-03-22 22:43 ` 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=20110322223156.GA10782@opensource.wolfsonmicro.com \
--to=broonie@opensource.wolfsonmicro.com \
--cc=collinsd@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@slimlogic.co.uk \
/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).