From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, "Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Douglas Anderson" <dianders@chromium.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"André Draszik" <andre.draszik@linaro.org>,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error
Date: Fri, 27 Nov 2026 18:35:41 +0000 [thread overview]
Message-ID: <20261127183624.3341010-2-lee@kernel.org> (raw)
In-Reply-To: <20261127183624.3341010-1-lee@kernel.org>
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
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(®ulator_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(®ulator_list_mutex);
regulator_ena_gpio_free(rdev);
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-27 18:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
2026-11-27 18:35 ` Lee Jones [this message]
2026-11-30 23:48 ` [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error Doug Anderson
2026-12-01 11:02 ` Lee Jones
2026-11-27 18:35 ` [PATCH 2/8] regulator: max8907: Duplicate of_regulator_match table per device Lee Jones
2026-11-27 18:35 ` [PATCH 3/8] regulator: tps6594-regulator: Use dedicated handler for external regulator IRQs Lee Jones
2026-11-27 18:35 ` [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config Lee Jones
2026-11-27 18:35 ` [PATCH 5/8] regulator: tps6594-regulator: Bind IRQ resources to child platform device Lee Jones
2026-11-27 18:35 ` [PATCH 6/8] regulator: core: Respect is_locked when disabling supply on enable failure Lee Jones
2026-11-27 18:35 ` [PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all() Lee Jones
2026-11-27 18:35 ` [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127183624.3341010-2-lee@kernel.org \
--to=lee@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=broonie@kernel.org \
--cc=dianders@chromium.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.