Skip to content

Commit 497330b

Browse files
andredbroonie
authored andcommitted
regulator: core: fix locking in regulator_resolve_supply() error path
If late enabling of a supply regulator fails in regulator_resolve_supply(), the code currently triggers a lockdep warning: WARNING: drivers/regulator/core.c:2649 at _regulator_put+0x80/0xa0, CPU#6: kworker/u32:4/596 ... Call trace: _regulator_put+0x80/0xa0 (P) regulator_resolve_supply+0x7cc/0xbe0 regulator_register_resolve_supply+0x28/0xb8 as the regulator_list_mutex must be held when calling _regulator_put(). To solve this, simply switch to using regulator_put(). While at it, we should also make sure that no concurrent access happens to our rdev while we clear out the supply pointer. Add appropriate locking to ensure that. While the code in question will be removed altogether in a follow-up commit, I believe it is still beneficial to have this corrected before removal for future reference. Fixes: 36a1f1b ("regulator: core: Fix memory leak in regulator_resolve_supply()") Fixes: 8e5356a ("regulator: core: Clear the supply pointer if enabling fails") Signed-off-by: André Draszik <andre.draszik@linaro.org> Link: https://patch.msgid.link/20260109-regulators-defer-v2-2-1a25dc968e60@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 96e7a88 commit 497330b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/regulator/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2285,8 +2285,16 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
22852285
if (rdev->use_count) {
22862286
ret = regulator_enable(rdev->supply);
22872287
if (ret < 0) {
2288-
_regulator_put(rdev->supply);
2288+
struct regulator *supply;
2289+
2290+
regulator_lock_two(rdev, rdev->supply->rdev, &ww_ctx);
2291+
2292+
supply = rdev->supply;
22892293
rdev->supply = NULL;
2294+
2295+
regulator_unlock_two(rdev, supply->rdev, &ww_ctx);
2296+
2297+
regulator_put(supply);
22902298
goto out;
22912299
}
22922300
}

0 commit comments

Comments
 (0)