diff options
author | Saravana Kannan <saravanak@google.com> | 2019-11-14 16:04:38 -0800 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-11-15 12:04:20 +0000 |
commit | b59b654478093fa429ad4c7897ae29f201146a00 (patch) | |
tree | 22ddcac704f51369284ac40c2b6b5a4e09033b62 /drivers/regulator/core.c | |
parent | 26c2c997aa1a6c5522f6619910ba025e53e69763 (diff) | |
download | linux-stable-b59b654478093fa429ad4c7897ae29f201146a00.tar.gz linux-stable-b59b654478093fa429ad4c7897ae29f201146a00.tar.bz2 linux-stable-b59b654478093fa429ad4c7897ae29f201146a00.zip |
regulator: core: Don't try to remove device links if add failed
device_link_add() might not always succeed depending on the type of
device link and the rest of the dependencies in the system. If
device_link_add() didn't succeed, then we shouldn't try to remove the
link later on as it might remove a link someone else created.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20191115000438.45970-1-saravanak@google.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 51ce280c1ce1..df49f35ae20f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1844,6 +1844,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, struct regulator_dev *rdev; struct regulator *regulator; const char *devname = dev ? dev_name(dev) : "deviceless"; + struct device_link *link; int ret; if (get_type >= MAX_GET_TYPE) { @@ -1951,7 +1952,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id, rdev->use_count = 0; } - device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); + link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); + if (!IS_ERR_OR_NULL(link)) + regulator->device_link = true; return regulator; } @@ -2046,7 +2049,8 @@ static void _regulator_put(struct regulator *regulator) debugfs_remove_recursive(regulator->debugfs); if (regulator->dev) { - device_link_remove(regulator->dev, &rdev->dev); + if (regulator->device_link) + device_link_remove(regulator->dev, &rdev->dev); /* remove any sysfs entries */ sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |