Skip to content

Commit 0591b14

Browse files
Rui Zhangbroonie
authored andcommitted
regulator: core: fix use_count leakage when handling boot-on
I found a use_count leakage towards supply regulator of rdev with boot-on option. ┌───────────────────┐ ┌───────────────────┐ │ regulator_dev A │ │ regulator_dev B │ │ (boot-on) │ │ (boot-on) │ │ use_count=0 │◀──supply──│ use_count=1 │ │ │ │ │ └───────────────────┘ └───────────────────┘ In case of rdev(A) configured with `regulator-boot-on', the use_count of supplying regulator(B) will increment inside regulator_enable(rdev->supply). Thus, B will acts like always-on, and further balanced regulator_enable/disable cannot actually disable it anymore. However, B was also configured with `regulator-boot-on', we wish it could be disabled afterwards. Signed-off-by: Rui Zhang <zr.zhang@vivo.com> Link: https://lore.kernel.org/r/20221201033806.2567812-1-zr.zhang@vivo.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f39f870 commit 0591b14

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/regulator/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,13 @@ static int set_machine_constraints(struct regulator_dev *rdev)
15961596
if (rdev->supply_name && !rdev->supply)
15971597
return -EPROBE_DEFER;
15981598

1599-
if (rdev->supply) {
1599+
/* If supplying regulator has already been enabled,
1600+
* it's not intended to have use_count increment
1601+
* when rdev is only boot-on.
1602+
*/
1603+
if (rdev->supply &&
1604+
(rdev->constraints->always_on ||
1605+
!regulator_is_enabled(rdev->supply))) {
16001606
ret = regulator_enable(rdev->supply);
16011607
if (ret < 0) {
16021608
_regulator_put(rdev->supply);

0 commit comments

Comments
 (0)