Skip to content

Commit 520fb17

Browse files
kohlschuetterbroonie
authored andcommitted
regulator: core: Fix regulator supply registration with sysfs
In "regulator: core: Resolve supply name earlier to prevent double-init", we introduced a bug that prevented the regulator names from registering properly with sysfs. Reorder regulator_register such that supply names are properly resolved and registered. Fixes: 8a866d5 ("regulator: core: Resolve supply name earlier to prevent double-init") Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Christian Kohlschütter <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b662748 commit 520fb17

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

drivers/regulator/core.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5409,6 +5409,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
54095409
bool dangling_of_gpiod = false;
54105410
struct device *dev;
54115411
int ret, i;
5412+
bool resolved_early = false;
54125413

54135414
if (cfg == NULL)
54145415
return ERR_PTR(-EINVAL);
@@ -5512,6 +5513,18 @@ regulator_register(const struct regulator_desc *regulator_desc,
55125513
BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
55135514
INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work);
55145515

5516+
if (init_data && init_data->supply_regulator)
5517+
rdev->supply_name = init_data->supply_regulator;
5518+
else if (regulator_desc->supply_name)
5519+
rdev->supply_name = regulator_desc->supply_name;
5520+
5521+
/* register with sysfs */
5522+
rdev->dev.class = &regulator_class;
5523+
rdev->dev.parent = dev;
5524+
dev_set_name(&rdev->dev, "regulator.%lu",
5525+
(unsigned long) atomic_inc_return(&regulator_no));
5526+
dev_set_drvdata(&rdev->dev, rdev);
5527+
55155528
/* set regulator constraints */
55165529
if (init_data)
55175530
rdev->constraints = kmemdup(&init_data->constraints,
@@ -5522,56 +5535,41 @@ regulator_register(const struct regulator_desc *regulator_desc,
55225535
GFP_KERNEL);
55235536
if (!rdev->constraints) {
55245537
ret = -ENOMEM;
5525-
goto clean;
5538+
goto wash;
55265539
}
55275540

5528-
if (init_data && init_data->supply_regulator)
5529-
rdev->supply_name = init_data->supply_regulator;
5530-
else if (regulator_desc->supply_name)
5531-
rdev->supply_name = regulator_desc->supply_name;
5532-
55335541
if ((rdev->supply_name && !rdev->supply) &&
5534-
(rdev->constraints->always_on ||
5535-
rdev->constraints->boot_on)) {
5536-
/* Try to resolve the name of the supplying regulator here first
5537-
* so we prevent double-initializing the regulator, which may
5538-
* cause timing-specific voltage brownouts/glitches that are
5539-
* hard to debug.
5540-
*/
5542+
(rdev->constraints->always_on ||
5543+
rdev->constraints->boot_on)) {
55415544
ret = regulator_resolve_supply(rdev);
55425545
if (ret)
55435546
rdev_dbg(rdev, "unable to resolve supply early: %pe\n",
55445547
ERR_PTR(ret));
5548+
5549+
resolved_early = true;
55455550
}
55465551

55475552
/* perform any regulator specific init */
55485553
if (init_data && init_data->regulator_init) {
55495554
ret = init_data->regulator_init(rdev->reg_data);
55505555
if (ret < 0)
5551-
goto clean;
5556+
goto wash;
55525557
}
55535558

55545559
if (config->ena_gpiod) {
55555560
ret = regulator_ena_gpio_request(rdev, config);
55565561
if (ret != 0) {
55575562
rdev_err(rdev, "Failed to request enable GPIO: %pe\n",
55585563
ERR_PTR(ret));
5559-
goto clean;
5564+
goto wash;
55605565
}
55615566
/* The regulator core took over the GPIO descriptor */
55625567
dangling_cfg_gpiod = false;
55635568
dangling_of_gpiod = false;
55645569
}
55655570

5566-
/* register with sysfs */
5567-
rdev->dev.class = &regulator_class;
5568-
rdev->dev.parent = dev;
5569-
dev_set_name(&rdev->dev, "regulator.%lu",
5570-
(unsigned long) atomic_inc_return(&regulator_no));
5571-
dev_set_drvdata(&rdev->dev, rdev);
5572-
55735571
ret = set_machine_constraints(rdev);
5574-
if (ret == -EPROBE_DEFER) {
5572+
if (ret == -EPROBE_DEFER && !resolved_early) {
55755573
/* Regulator might be in bypass mode and so needs its supply
55765574
* to set the constraints
55775575
*/

0 commit comments

Comments
 (0)