Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Saravana Kannan and committed by
Mark Brown
b59b6544 26c2c997

+7 -2
+6 -2
drivers/regulator/core.c
··· 1844 1844 struct regulator_dev *rdev; 1845 1845 struct regulator *regulator; 1846 1846 const char *devname = dev ? dev_name(dev) : "deviceless"; 1847 + struct device_link *link; 1847 1848 int ret; 1848 1849 1849 1850 if (get_type >= MAX_GET_TYPE) { ··· 1952 1951 rdev->use_count = 0; 1953 1952 } 1954 1953 1955 - device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); 1954 + link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS); 1955 + if (!IS_ERR_OR_NULL(link)) 1956 + regulator->device_link = true; 1956 1957 1957 1958 return regulator; 1958 1959 } ··· 2049 2046 debugfs_remove_recursive(regulator->debugfs); 2050 2047 2051 2048 if (regulator->dev) { 2052 - device_link_remove(regulator->dev, &rdev->dev); 2049 + if (regulator->device_link) 2050 + device_link_remove(regulator->dev, &rdev->dev); 2053 2051 2054 2052 /* remove any sysfs entries */ 2055 2053 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
+1
drivers/regulator/internal.h
··· 36 36 struct list_head list; 37 37 unsigned int always_on:1; 38 38 unsigned int bypass:1; 39 + unsigned int device_link:1; 39 40 int uA_load; 40 41 unsigned int enable_count; 41 42 unsigned int deferred_disables;