Commit b59b6544 authored by Saravana Kannan's avatar Saravana Kannan Committed by Mark Brown

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: default avatarSaravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20191115000438.45970-1-saravanak@google.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 26c2c997
...@@ -1844,6 +1844,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, ...@@ -1844,6 +1844,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
struct regulator_dev *rdev; struct regulator_dev *rdev;
struct regulator *regulator; struct regulator *regulator;
const char *devname = dev ? dev_name(dev) : "deviceless"; const char *devname = dev ? dev_name(dev) : "deviceless";
struct device_link *link;
int ret; int ret;
if (get_type >= MAX_GET_TYPE) { if (get_type >= MAX_GET_TYPE) {
...@@ -1951,7 +1952,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id, ...@@ -1951,7 +1952,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
rdev->use_count = 0; 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; return regulator;
} }
...@@ -2046,6 +2049,7 @@ static void _regulator_put(struct regulator *regulator) ...@@ -2046,6 +2049,7 @@ static void _regulator_put(struct regulator *regulator)
debugfs_remove_recursive(regulator->debugfs); debugfs_remove_recursive(regulator->debugfs);
if (regulator->dev) { if (regulator->dev) {
if (regulator->device_link)
device_link_remove(regulator->dev, &rdev->dev); device_link_remove(regulator->dev, &rdev->dev);
/* remove any sysfs entries */ /* remove any sysfs entries */
......
...@@ -36,6 +36,7 @@ struct regulator { ...@@ -36,6 +36,7 @@ struct regulator {
struct list_head list; struct list_head list;
unsigned int always_on:1; unsigned int always_on:1;
unsigned int bypass:1; unsigned int bypass:1;
unsigned int device_link:1;
int uA_load; int uA_load;
unsigned int enable_count; unsigned int enable_count;
unsigned int deferred_disables; unsigned int deferred_disables;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment