[PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error

From: Lee Jones

Date: Fri Nov 27 2026 - 13:36:44 EST


When enabling rdev->supply fails in set_machine_constraints(), the error
path calls _regulator_put(rdev->supply) without holding
regulator_list_mutex and clears rdev->supply to NULL. Neither
regulator_register() nor regulator_resolve_supply() holds
regulator_list_mutex here, and when called from
regulator_resolve_supply() under regulator_lock_dependent(), clearing
rdev->supply prevents regulator_unlock_dependent() from unlocking the
supply chain and skips unregister_regulator_event_forwarding().

In addition, the wash error label in regulator_register() releases
rdev->supply and drops the device reference without calling
unregister_regulator_event_forwarding(), leaving a dangling notifier on
the supply chain after rdev is freed.

Leave supply teardown in set_machine_constraints() to its callers, which
already handle cleanup with proper locking, and unregister event
forwarding before putting rdev->supply on the regulator_register() error
path.

Fixes: 05f224ca6693 ("regulator: core: Clean enabling always-on regulators + their supplies")
Fixes: 433e294c3c5b ("regulator: core: forward undervoltage events downstream by default")
Fixes: 8d38423d9dea ("regulator: core: don't fail regulator_register() with missing required supply")
Closes: https://sashiko.dev/#/bug/linux-f6e93cf6-c907-4a0b-b748-617186aee410
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/regulator/core.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 8bb1ae4e03ea..18ec8b77e620 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1680,11 +1680,8 @@ static int set_machine_constraints(struct regulator_dev *rdev,
ret = (is_locked
? _regulator_enable(rdev->supply, NULL)
: regulator_enable(rdev->supply));
- if (ret < 0) {
- _regulator_put(rdev->supply);
- rdev->supply = NULL;
+ if (ret < 0)
return ret;
- }
supply_enabled = true;
}

@@ -6392,7 +6389,10 @@ regulator_register(struct device *dev,
regulator_remove_coupling(rdev);
mutex_unlock(&regulator_list_mutex);
wash:
- regulator_put(rdev->supply);
+ if (rdev->supply) {
+ unregister_regulator_event_forwarding(rdev);
+ regulator_put(rdev->supply);
+ }
kfree(rdev->coupling_desc.coupled_rdevs);
mutex_lock(&regulator_list_mutex);
regulator_ena_gpio_free(rdev);
--
2.56.1.839.g22a8290db9-goog