The sysfs device link can only be created after regulator device registered.
Fixes: c438b9d017362 ("regulator: core: Move registration of regulator device") Signed-off-by: Jeffy Chen <jeffy.c...@rock-chips.com> --- drivers/regulator/core.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2c66b528aedec..36e650b61f7a9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1405,12 +1405,15 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, if (regulator->supply_name == NULL) goto overflow_err; - err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, - buf); - if (err) { - rdev_dbg(rdev, "could not add device link %s err %d\n", - dev->kobj.name, err); - /* non-fatal */ + if (device_is_registered(dev)) { + err = sysfs_create_link_nowarn(&rdev->dev.kobj, + &dev->kobj, buf); + if (err) { + rdev_dbg(rdev, + "could not add device link %s err %d\n", + dev->kobj.name, err); + /* non-fatal */ + } } } else { regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL); @@ -4416,6 +4419,18 @@ regulator_register(const struct regulator_desc *regulator_desc, goto unset_supplies; } + /* Add a link to the device sysfs entry */ + if (rdev->supply && rdev->supply->dev) { + ret = sysfs_create_link_nowarn(&rdev->supply->dev->kobj, + &rdev->dev.kobj, + rdev->supply->supply_name); + if (ret) { + rdev_dbg(rdev, "could not add device link %s err %d\n", + rdev->dev.kobj.name, ret); + /* non-fatal */ + } + } + rdev_init_debugfs(rdev); /* try to resolve regulators supply since a new one was registered */ -- 2.11.0