Skip to contentSkip to conversation

regulator: fix race with probing of dummy regulator

PATCH In review Christian Eggers 2 participants 5 messages Mar 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover regulator: fix race with probing of dummy regulator

These two patches are already in linux-next. I made a minor adjustment proposed by Doug. Can they still be updated?

#1 lore raw

PATCH v3 1/2 regulator: dummy: force synchronous probing

Sometimes I get a NULL pointer dereference at boot time in kobject_get() with the following call stack:

anatop_regulator_probe()
devm_regulator_register()
regulator_register()
regulator_resolve_supply()
kobject_get()

By placing some extra BUG_ON() statements I could verify that this is raised because probing of the 'dummy' regulator driver is not completed ('dummy_regulator_rdev' is still NULL).

In the JTAG debugger I can see that dummy_regulator_probe() and anatop_regulator_probe() can be run by different kernel threads (kworker/u4:*). I haven't further investigated whether this can be changed or if there are other possibilities to force synchronization between these two probe routines. On the other hand I don't expect much boot time penalty by probing the 'dummy' regulator synchronously.

Fixes 259b93b21a9f ("regulator: Set PROBE_PREFER_ASYNCHRONOUS for drivers that existed in 4.14")

---
v2:
- no changes

v3:
- no changes

 drivers/regulator/dummy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/dummy.c +1 -1
index 5b9b9e4e762d..9f59889129ab 100644
@@ -60,7 +60,7 @@ static struct platform_driver dummy_regulator_driver = {
 	.probe		= dummy_regulator_probe,
 	.driver		= {
 		.name		= "reg-dummy",
-		.probe_type	= PROBE_PREFER_ASYNCHRONOUS,
+		.probe_type	= PROBE_FORCE_SYNCHRONOUS,
 	},
 };
 
Signature · 1 line
2.44.1
#2 lore raw

PATCH v3 2/2 regulator: check that dummy regulator has been probed before using it

In reply to Christian Eggers

Due to asynchronous driver probing there is a chance that the dummy regulator hasn't already been probed when first accessing it.

---
v2:
- return -EPROBE_DEFER rather than using BUG_ON()

v3:
- move dev_warn() below returning -EPROBE_DEFER

 drivers/regulator/core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/regulator/core.c +11 -1
index 4ddf0efead68..4d0f13899e6b 100644
@@ -2069,6 +2069,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 
 		if (have_full_constraints()) {
 			r = dummy_regulator_rdev;
+			if (!r) {
+				ret = -EPROBE_DEFER;
+				goto out;
+			}
 			get_device(&r->dev);
 		} else {
 			dev_err(dev, "Failed to resolve %s-supply for %s\n",
@@ -2086,6 +2090,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 			goto out;
 		}
 		r = dummy_regulator_rdev;
+		if (!r) {
+			ret = -EPROBE_DEFER;
+			goto out;
+		}
 		get_device(&r->dev);
 	}
 
@@ -2211,8 +2219,10 @@ struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct devic
 			 * enabled, even if it isn't hooked up, and just
 			 * provide a dummy.
 			 */
-			dev_warn(dev, "supply %s not found, using dummy regulator\n", id);
 			rdev = dummy_regulator_rdev;
+			if (!rdev)
+				return ERR_PTR(-EPROBE_DEFER);
+			dev_warn(dev, "supply %s not found, using dummy regulator\n", id);
 			get_device(&rdev->dev);
 			break;
 
Signature · 1 line
2.44.1
maintainer
#3 lore raw

Re: [PATCH v3 2/2] regulator: check that dummy regulator has been probed before using it

Quoted 2 lines · Christian Eggers

Due to asynchronous driver probing there is a chance that the dummy regulator hasn't already been probed when first accessing it.

Please do not submit new versions of already applied patches, please submit incremental updates to the existing code. Modifying existing commits creates problems for other users building on top of those commits so it's best practice to only change pubished git commits if absolutely essential.

maintainer
#4 lore raw

Re: (subset) [PATCH v3 0/2] regulator: fix race with probing of dummy regulator

In reply to Christian Eggers
Quoted 3 lines · Christian Eggers

These two patches are already in linux-next. I made a minor adjustment proposed by Doug. Can they still be updated?

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[2/2] regulator: check that dummy regulator has been probed before using it

      commit: 2c7a50bec4958f1d1c84d19cde518d0e96a676fd

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark