Merge branch 'regulator-5.5' into regulator-linus
[muen/linux.git] / drivers / regulator / core.c
index 5bab251..d015d99 100644 (file)
@@ -1850,6 +1850,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) {
@@ -1957,7 +1958,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;
 }
@@ -2052,7 +2055,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);
@@ -5213,6 +5217,7 @@ unset_supplies:
        regulator_remove_coupling(rdev);
        mutex_unlock(&regulator_list_mutex);
 wash:
+       kfree(rdev->coupling_desc.coupled_rdevs);
        kfree(rdev->constraints);
        mutex_lock(&regulator_list_mutex);
        regulator_ena_gpio_free(rdev);