]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
regulator: core: Don't try to remove device links if add failed
authorSaravana Kannan <saravanak@google.com>
Fri, 15 Nov 2019 00:04:38 +0000 (16:04 -0800)
committerMark Brown <broonie@kernel.org>
Fri, 15 Nov 2019 12:04:20 +0000 (12:04 +0000)
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>
drivers/regulator/core.c
drivers/regulator/internal.h

index 51ce280c1ce1360d1bf9a503cfb88b8e88a66fe2..df49f35ae20f38f8eb7df373e2c3861b47552b9d 100644 (file)
@@ -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);
index 83ae442f515b66ad2385057c00cb566c5be3784c..2391b565ef11f34f616850e8cdc8a5b3a78c9f8c 100644 (file)
@@ -36,6 +36,7 @@ struct regulator {
        struct list_head list;
        unsigned int always_on:1;
        unsigned int bypass:1;
+       unsigned int device_link:1;
        int uA_load;
        unsigned int enable_count;
        unsigned int deferred_disables;