mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regulator: core: Fix device link error when registering regulator
@ 2018-10-11 11:32 Jeffy Chen
  0 siblings, 0 replies; only message in thread
From: Jeffy Chen @ 2018-10-11 11:32 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jeffy Chen, Liam Girdwood, Mark Brown

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.chen@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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-11 11:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-11 11:32 [PATCH] regulator: core: Fix device link error when registering regulator Jeffy Chen

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®