Skip to contentSkip to conversation

regulator: core: grab supply info before unlocking

PATCH In review John Ogness 2 participants 2 messages Apr 22, 2016 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: core: grab supply info before unlocking

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.

---
patch against next-20160421

 drivers/regulator/core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/core.c +2 -2
index 9348c78..629f92f 100644
@@ -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;
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 4 lines · John Ogness

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"?