Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Rui Zhang and committed by
Mark Brown
0591b14c f39f8709

+7 -1
+7 -1
drivers/regulator/core.c
··· 1596 1596 if (rdev->supply_name && !rdev->supply) 1597 1597 return -EPROBE_DEFER; 1598 1598 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))) { 1600 1606 ret = regulator_enable(rdev->supply); 1601 1607 if (ret < 0) { 1602 1608 _regulator_put(rdev->supply);