public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: core: grab supply info before unlocking
@ 2016-04-22 14:33 John Ogness
  2016-04-22 15:07 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: John Ogness @ 2016-04-22 14:33 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

It is necessary to check if there is a supply while still holding
the regulator lock. Otherwise a theoretical race can occur that
someone else can add a supply and then we incorrectly try to
unlock that newly added regulator.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 patch against next-20160421

 drivers/regulator/core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9348c78..629f92f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -161,10 +161,10 @@ static void regulator_unlock_supply(struct regulator_dev *rdev)
 	struct regulator *supply;
 
 	while (1) {
-		mutex_unlock(&rdev->mutex);
 		supply = rdev->supply;
+		mutex_unlock(&rdev->mutex);
 
-		if (!rdev->supply)
+		if (!supply)
 			return;
 
 		rdev = supply->rdev;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regulator: core: grab supply info before unlocking
  2016-04-22 14:33 [PATCH] regulator: core: grab supply info before unlocking John Ogness
@ 2016-04-22 15:07 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2016-04-22 15:07 UTC (permalink / raw)
  To: John Ogness; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

On Fri, Apr 22, 2016 at 04:33:51PM +0200, John Ogness wrote:
> It is necessary to check if there is a supply while still holding
> the regulator lock. Otherwise a theoretical race can occur that
> someone else can add a supply and then we incorrectly try to
> unlock that newly added regulator.

I don't understand this.  What do you mean by "add a supply"?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-22 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-22 14:33 [PATCH] regulator: core: grab supply info before unlocking John Ogness
2016-04-22 15:07 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox