[PATCH] regulator: core: lock device when calling device_is_bound()

Bartosz Golaszewski posted 1 patch 6 days, 18 hours ago
drivers/regulator/core.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
[PATCH] regulator: core: lock device when calling device_is_bound()
Posted by Bartosz Golaszewski 6 days, 18 hours ago
device_is_bound() must be called with the device lock taken. Add missing
synchronization in regulator_resolve_supply().

Fixes: 66d228a2bf03 ("regulator: core: Don't use regulators as supplies until the parent is bound")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/regulator/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index dc5d67767336..1274a1ff8e17 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2240,10 +2240,12 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 	 * device get probe deferred and unregisters the supply.
 	 */
 	if (r->dev.parent && r->dev.parent != rdev->dev.parent) {
-		if (!device_is_bound(r->dev.parent)) {
-			put_device(&r->dev);
-			ret = -EPROBE_DEFER;
-			goto out;
+		scoped_guard(device, r->dev.parent) {
+			if (!device_is_bound(r->dev.parent)) {
+				put_device(&r->dev);
+				ret = -EPROBE_DEFER;
+				goto out;
+			}
 		}
 	}
 
-- 
2.47.3
Re: [PATCH] regulator: core: lock device when calling device_is_bound()
Posted by Mark Brown 5 days, 17 hours ago
On Mon, May 18, 2026 at 12:20:15PM +0200, Bartosz Golaszewski wrote:

> @@ -2240,10 +2240,12 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
>  	 * device get probe deferred and unregisters the supply.
>  	 */
>  	if (r->dev.parent && r->dev.parent != rdev->dev.parent) {
> -		if (!device_is_bound(r->dev.parent)) {
> -			put_device(&r->dev);
> -			ret = -EPROBE_DEFER;
> -			goto out;
> +		scoped_guard(device, r->dev.parent) {
> +			if (!device_is_bound(r->dev.parent)) {
> +				put_device(&r->dev);
> +				ret = -EPROBE_DEFER;
> +				goto out;
> +			}

How does this work if a regulator is being registered in the context of
a MFD registering it's children from probe()?

I'm also not convinced that mixing a scoped guard into the middle of
goto based cleanup is the best thing.
Re: [PATCH] regulator: core: lock device when calling device_is_bound()
Posted by Bartosz Golaszewski 5 days, 17 hours ago
On Tue, May 19, 2026 at 1:15 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, May 18, 2026 at 12:20:15PM +0200, Bartosz Golaszewski wrote:
>
> > @@ -2240,10 +2240,12 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
> >        * device get probe deferred and unregisters the supply.
> >        */
> >       if (r->dev.parent && r->dev.parent != rdev->dev.parent) {
> > -             if (!device_is_bound(r->dev.parent)) {
> > -                     put_device(&r->dev);
> > -                     ret = -EPROBE_DEFER;
> > -                     goto out;
> > +             scoped_guard(device, r->dev.parent) {
> > +                     if (!device_is_bound(r->dev.parent)) {
> > +                             put_device(&r->dev);
> > +                             ret = -EPROBE_DEFER;
> > +                             goto out;
> > +                     }
>
> How does this work if a regulator is being registered in the context of
> a MFD registering it's children from probe()?
>

Yeah, I've seen the comment from sashiko. I don't have an idea that
doesn't involve a serious rework, so we may drop this patch. After all
it worked without issues so far.

Bart

> I'm also not convinced that mixing a scoped guard into the middle of
> goto based cleanup is the best thing.