From: Charles Keepax Date: Tue, 13 Jun 2017 15:12:47 +0000 (+0100) Subject: regulator: core: Prioritise consumer mappings over regulator name X-Git-Tag: v4.13-rc1~176^2~3^2~1 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=062171973e05440673cb997e64395e84a8e66350;p=karo-tx-linux.git regulator: core: Prioritise consumer mappings over regulator name Currently, when looking up a regulator supply, the regulator name takes priority over the consumer mappings. As there are a lot of regulator names that are in fairly common use (VDD, MICVDD, etc.) this can easily lead to obtaining the wrong supply, when a system contains two regulators that share a name. The explicit consumer mappings contain much less ambiguity as they specify both a name and a consumer device. As such prioritise those if one exists and only fall back to the regulator name if there are no matching explicit mappings. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index c0d9ae8d0860..a0362a63902e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1462,7 +1462,7 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name) static struct regulator_dev *regulator_dev_lookup(struct device *dev, const char *supply) { - struct regulator_dev *r; + struct regulator_dev *r = NULL; struct device_node *node; struct regulator_map *map; const char *devname = NULL; @@ -1489,10 +1489,6 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, if (dev) devname = dev_name(dev); - r = regulator_lookup_by_name(supply); - if (r) - return r; - mutex_lock(®ulator_list_mutex); list_for_each_entry(map, ®ulator_map_list, list) { /* If the mapping has a device set up it must match */ @@ -1508,6 +1504,10 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, } mutex_unlock(®ulator_list_mutex); + if (r) + return r; + + r = regulator_lookup_by_name(supply); if (r) return r;