On Tue, Jan 12, 2021 at 10:34:19PM +0100, Marek Szyprowski wrote:

> ======================================================
> WARNING: possible circular locking dependency detected
> 5.11.0-rc1-00008-geaa7995c529b #10095 Not tainted
> ------------------------------------------------------
> swapper/0/1 is trying to acquire lock:
> c12e1b80 (regulator_list_mutex){+.+.}-{3:3}, at: 
> regulator_lock_dependent+0x4c/0x2b0

If you're sending backtraces or other enormous reports like this please
run them through addr2line first so that things are a bit more leigible.

> but task is already holding lock:
> df7190c0 (regulator_ww_class_mutex){+.+.}-{3:3}, at: 
> regulator_resolve_supply+0x44/0x318
> 
> which lock already depends on the new lock.

Does this help (completely untested):

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 3ae5ccd9277d..7d1422b00974 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1823,17 +1823,6 @@ static int regulator_resolve_supply(struct regulator_dev 
*rdev)
        if (rdev->supply)
                return 0;
 
-       /*
-        * Recheck rdev->supply with rdev->mutex lock held to avoid a race
-        * between rdev->supply null check and setting rdev->supply in
-        * set_supply() from concurrent tasks.
-        */
-       regulator_lock(rdev);
-
-       /* Supply just resolved by a concurrent task? */
-       if (rdev->supply)
-               goto out;
-
        r = regulator_dev_lookup(dev, rdev->supply_name);
        if (IS_ERR(r)) {
                ret = PTR_ERR(r);
@@ -1885,10 +1874,23 @@ static int regulator_resolve_supply(struct 
regulator_dev *rdev)
                goto out;
        }
 
+       /*
+        * Recheck rdev->supply with rdev->mutex lock held to avoid a race
+        * between rdev->supply null check and setting rdev->supply in
+        * set_supply() from concurrent tasks.
+        */
+       regulator_lock(rdev);
+
+       /* Supply just resolved by a concurrent task? */
+       if (rdev->supply) {
+               put_device(&r->dev);
+               goto out_rdev_lock;
+       }
+
        ret = set_supply(rdev, r);
        if (ret < 0) {
                put_device(&r->dev);
-               goto out;
+               goto out_rdev_lock;
        }
 
        /*
@@ -1901,12 +1903,13 @@ static int regulator_resolve_supply(struct 
regulator_dev *rdev)
                if (ret < 0) {
                        _regulator_put(rdev->supply);
                        rdev->supply = NULL;
-                       goto out;
+                       goto out_rdev_lock;
                }
        }
 
-out:
+out_rdev_lock:
        regulator_unlock(rdev);
+out:
        return ret;
 }
 

Attachment: signature.asc
Description: PGP signature

Reply via email to