Re: [PATCH 05/10] regulator: core: Hold supply device reference until constraints are resolved in regulator_resolve_supply()
From: André Draszik
Date: Thu Nov 05 2026 - 12:36:56 EST
Hi Lee,
Overall looks good, thanks for catching this. A few small comments
below:
On Wed, 2026-11-04 at 18:20 +0000, Lee Jones wrote:
> 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think
"called put_device(&r->dev) immediately" or
"dropped its reference immediately" reads a little bit better.
> 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
[...]
> @@ -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;
> }
There are three locations in this file that still do
'put_device(&r->dev); goto out;' in this function and could be updated
as well:
* the '!device_is_bound(r->dev.parent) exit' around line 2264
* the exit after regulator_resolve_supply(r) fails around line 2275
* the 'if (r == rdev) {' branch around line 2242 (with a little massaging)
Then there'd be just one place that releases the lookup reference.
Cheers,
Andre'