From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, "Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"André Draszik" <andre.draszik@linaro.org>,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 05/10] regulator: core: Hold supply device reference until constraints are resolved in regulator_resolve_supply()
Date: Wed, 4 Nov 2026 18:20:55 +0000 [thread overview]
Message-ID: <20261104182148.1176116-6-lee@kernel.org> (raw)
In-Reply-To: <20261104182148.1176116-1-lee@kernel.org>
In regulator_resolve_supply(), set_supply() previously consumed the
caller's lookup reference on &r->dev without taking its own reference
for rdev->supply, while the concurrent path (when rdev->supply was
already set) dropped put_device(&r->dev) immediately after unlocking
and before retrying set_machine_constraints(). In both paths, if
set_machine_constraints() fails (which may drop rdev->supply inside
set_machine_constraints() or race with a concurrent task in
unset_supply), the error path subsequently passes r to
regulator_lock_two(rdev, r, &ww_ctx) without holding a guaranteed local
reference on &r->dev.
Take a dedicated device reference for rdev->supply in set_supply() to
match _regulator_put(), and retain the local lookup reference on &r->dev
throughout regulator_resolve_supply() until returning.
Fixes: 8d38423d9dea ("regulator: core: don't fail regulator_register() with missing required supply")
Closes: https://sashiko.dev/#/bug/linux-3a22ff58-1a66-4a6a-9e19-83135ef603e0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/core.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 935fee27f126..6d522731e4d9 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1842,6 +1842,7 @@ static int set_supply(struct regulator_dev *rdev,
err = -ENOMEM;
return err;
}
+ get_device(&supply_rdev->dev);
supply_rdev->open_count++;
return 0;
@@ -2290,22 +2291,20 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
supply = rdev->supply;
regulator_unlock_two(rdev, r, &ww_ctx);
- put_device(&r->dev);
/*
* Supply resolved by concurrent task, and constraints set as
* well (or not required): fast path.
*/
if (done)
- goto out;
+ goto out_put;
do_final_setup = false;
} else {
ret = set_supply(rdev, r);
if (ret < 0) {
regulator_unlock_two(rdev, r, &ww_ctx);
- put_device(&r->dev);
- goto out;
+ goto out_put;
}
supply = rdev->supply;
@@ -2342,7 +2341,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
*/
regulator_unlock_dependent(rdev, &ww_ctx);
ret = -EPROBE_DEFER;
- goto out;
+ goto out_put;
}
ret = set_machine_constraints(rdev, true);
@@ -2364,7 +2363,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
* that again via unset_supply.
*/
regulator_unlock_two(rdev, r, &ww_ctx);
- goto out;
+ goto out_put;
}
unregister_regulator_event_forwarding(rdev);
@@ -2376,11 +2375,13 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
regulator_unlock_dependent(rdev, &ww_ctx);
if (!do_final_setup)
- goto out;
+ goto out_put;
/* rdev->supply was created in set_supply() */
link_and_create_debugfs(rdev->supply, rdev->supply->rdev, &rdev->dev);
+out_put:
+ put_device(&r->dev);
out:
return ret;
@@ -2391,6 +2392,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
regulator_unlock_two(rdev, supply->rdev, &ww_ctx);
regulator_put(supply);
+ put_device(&r->dev);
return ret;
}
--
2.56.0.385.gac671c819a-goog
next prev parent reply other threads:[~2026-11-04 18:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 18:20 [PATCH 00/10] regulator: Fix teardown races, reference counting, and error handling Lee Jones
2026-11-04 18:20 ` [PATCH 01/10] regulator: irq_helpers: Clear caller handle in regulator_irq_helper_cancel() Lee Jones
2026-11-04 18:20 ` [PATCH 02/10] regulator: arizona-ldo1: Avoid double gpiod_put() on enable GPIO Lee Jones
2026-11-04 18:20 ` [PATCH 03/10] regulator: core: Flush delayed disable_work before releasing supply in regulator_unregister() Lee Jones
2026-11-04 18:20 ` [PATCH 04/10] regulator: arizona-micsupp: Cancel check_cp_work on device teardown Lee Jones
2026-11-04 18:20 ` Lee Jones [this message]
2026-11-04 18:20 ` [PATCH 06/10] regulator: core: Use ktime_get_boottime() in set_machine_constraints() Lee Jones
2026-11-04 18:20 ` [PATCH 07/10] regulator: bq257xx: Propagate GPIO error in bq257xx_reg_dt_parse_gpio() Lee Jones
2026-11-04 18:20 ` [PATCH 08/10] regulator: tps6594-regulator: Fix LDO4 n_voltages in tps6594_ldo_regs Lee Jones
2026-11-04 18:20 ` [PATCH 09/10] regulator: max8907: Avoid NULL idata dereference in max8907_regulator_probe() Lee Jones
2026-11-04 18:21 ` [PATCH 10/10] regulator: rt6190: Check pm_runtime_resume_and_get() return value in rt6190_out_enable() 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=20261104182148.1176116-6-lee@kernel.org \
--to=lee@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®