mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regulator: core: lock device when calling device_is_bound()
@ 2026-05-18 10:20 Bartosz Golaszewski
  2026-05-19 10:40 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-18 10:20 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jon Hunter; +Cc: linux-kernel, Bartosz Golaszewski

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: core: lock device when calling device_is_bound()
  2026-05-18 10:20 [PATCH] regulator: core: lock device when calling device_is_bound() Bartosz Golaszewski
@ 2026-05-19 10:40 ` Mark Brown
  2026-05-19 11:29   ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2026-05-19 10:40 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Liam Girdwood, Jon Hunter, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 801 bytes --]

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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: core: lock device when calling device_is_bound()
  2026-05-19 10:40 ` Mark Brown
@ 2026-05-19 11:29   ` Bartosz Golaszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-19 11:29 UTC (permalink / raw)
  To: Mark Brown; +Cc: Bartosz Golaszewski, Liam Girdwood, Jon Hunter, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-19 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-18 10:20 [PATCH] regulator: core: lock device when calling device_is_bound() Bartosz Golaszewski
2026-05-19 10:40 ` Mark Brown
2026-05-19 11:29   ` Bartosz Golaszewski

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®