[PATCH] regulator: core: grab supply info before unlocking

From: John Ogness
Date: Fri Apr 22 2016 - 10:33:59 EST


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@xxxxxxxxxxxxx>
---
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