提交 163478da 编写于 作者: D Dmitry Torokhov 提交者: Mark Brown

regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

Instead of returning both regulator_dev structure as return value and
auxiliary error code in 'ret' argument, let's switch to using ERR_PTR
encoded values. This makes it more obvious what is going on at call sites.

Also, let's not unlock the mutex in the middle of a loop, but rather break
out and have single unlock path.
Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 d1642ea7
...@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name) ...@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
* lookup could succeed in the future. * lookup could succeed in the future.
* *
* If successful, returns a struct regulator_dev that corresponds to the name * If successful, returns a struct regulator_dev that corresponds to the name
* @supply and with the embedded struct device refcount incremented by one, * @supply and with the embedded struct device refcount incremented by one.
* or NULL on failure. The refcount must be dropped by calling put_device(). * The refcount must be dropped by calling put_device().
* On failure one of the following ERR-PTR-encoded values is returned:
* -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed
* in the future.
*/ */
static struct regulator_dev *regulator_dev_lookup(struct device *dev, static struct regulator_dev *regulator_dev_lookup(struct device *dev,
const char *supply, const char *supply)
int *ret)
{ {
struct regulator_dev *r; struct regulator_dev *r;
struct device_node *node; struct device_node *node;
...@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, ...@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
r = of_find_regulator_by_node(node); r = of_find_regulator_by_node(node);
if (r) if (r)
return r; return r;
*ret = -EPROBE_DEFER;
return NULL;
} else {
/* /*
* If we couldn't even get the node then it's * We have a node, but there is no device.
* not just that the device didn't register * assume it has not registered yet.
* yet, there's no node and we'll never
* succeed.
*/ */
*ret = -ENODEV; return ERR_PTR(-EPROBE_DEFER);
} }
} }
...@@ -1506,13 +1504,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, ...@@ -1506,13 +1504,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
if (strcmp(map->supply, supply) == 0 && if (strcmp(map->supply, supply) == 0 &&
get_device(&map->regulator->dev)) { get_device(&map->regulator->dev)) {
mutex_unlock(&regulator_list_mutex); r = map->regulator;
return map->regulator; break;
} }
} }
mutex_unlock(&regulator_list_mutex); mutex_unlock(&regulator_list_mutex);
return NULL; if (r)
return r;
return ERR_PTR(-ENODEV);
} }
static int regulator_resolve_supply(struct regulator_dev *rdev) static int regulator_resolve_supply(struct regulator_dev *rdev)
...@@ -1529,8 +1530,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) ...@@ -1529,8 +1530,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
if (rdev->supply) if (rdev->supply)
return 0; return 0;
r = regulator_dev_lookup(dev, rdev->supply_name, &ret); r = regulator_dev_lookup(dev, rdev->supply_name);
if (!r) { if (IS_ERR(r)) {
ret = PTR_ERR(r);
if (ret == -ENODEV) { if (ret == -ENODEV) {
/* /*
* No supply was specified for this regulator and * No supply was specified for this regulator and
...@@ -1601,10 +1604,11 @@ struct regulator *_regulator_get(struct device *dev, const char *id, ...@@ -1601,10 +1604,11 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
if (dev) if (dev)
devname = dev_name(dev); devname = dev_name(dev);
rdev = regulator_dev_lookup(dev, id, &ret); rdev = regulator_dev_lookup(dev, id);
if (rdev) if (!IS_ERR(rdev))
goto found; goto found;
ret = PTR_ERR(rdev);
regulator = ERR_PTR(ret); regulator = ERR_PTR(ret);
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册