diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-02-04 13:19:21 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-02-05 11:36:40 -0500 |
commit | 163478dae0b6ce2437488e54012705b53ef43f3d (patch) | |
tree | 5211e13ebc37a571cc0f8631bbba99624a5c2653 | |
parent | d1642ea717be09039114dad57a8ae08d77f17dfb (diff) |
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: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/core.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 867756651544..3e246c82939d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name) | |||
1455 | * lookup could succeed in the future. | 1455 | * lookup could succeed in the future. |
1456 | * | 1456 | * |
1457 | * If successful, returns a struct regulator_dev that corresponds to the name | 1457 | * If successful, returns a struct regulator_dev that corresponds to the name |
1458 | * @supply and with the embedded struct device refcount incremented by one, | 1458 | * @supply and with the embedded struct device refcount incremented by one. |
1459 | * or NULL on failure. The refcount must be dropped by calling put_device(). | 1459 | * The refcount must be dropped by calling put_device(). |
1460 | * On failure one of the following ERR-PTR-encoded values is returned: | ||
1461 | * -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed | ||
1462 | * in the future. | ||
1460 | */ | 1463 | */ |
1461 | static struct regulator_dev *regulator_dev_lookup(struct device *dev, | 1464 | static struct regulator_dev *regulator_dev_lookup(struct device *dev, |
1462 | const char *supply, | 1465 | const char *supply) |
1463 | int *ret) | ||
1464 | { | 1466 | { |
1465 | struct regulator_dev *r; | 1467 | struct regulator_dev *r; |
1466 | struct device_node *node; | 1468 | struct device_node *node; |
@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, | |||
1476 | r = of_find_regulator_by_node(node); | 1478 | r = of_find_regulator_by_node(node); |
1477 | if (r) | 1479 | if (r) |
1478 | return r; | 1480 | return r; |
1479 | *ret = -EPROBE_DEFER; | 1481 | |
1480 | return NULL; | ||
1481 | } else { | ||
1482 | /* | 1482 | /* |
1483 | * If we couldn't even get the node then it's | 1483 | * We have a node, but there is no device. |
1484 | * not just that the device didn't register | 1484 | * assume it has not registered yet. |
1485 | * yet, there's no node and we'll never | ||
1486 | * succeed. | ||
1487 | */ | 1485 | */ |
1488 | *ret = -ENODEV; | 1486 | return ERR_PTR(-EPROBE_DEFER); |
1489 | } | 1487 | } |
1490 | } | 1488 | } |
1491 | 1489 | ||
@@ -1506,13 +1504,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, | |||
1506 | 1504 | ||
1507 | if (strcmp(map->supply, supply) == 0 && | 1505 | if (strcmp(map->supply, supply) == 0 && |
1508 | get_device(&map->regulator->dev)) { | 1506 | get_device(&map->regulator->dev)) { |
1509 | mutex_unlock(®ulator_list_mutex); | 1507 | r = map->regulator; |
1510 | return map->regulator; | 1508 | break; |
1511 | } | 1509 | } |
1512 | } | 1510 | } |
1513 | mutex_unlock(®ulator_list_mutex); | 1511 | mutex_unlock(®ulator_list_mutex); |
1514 | 1512 | ||
1515 | return NULL; | 1513 | if (r) |
1514 | return r; | ||
1515 | |||
1516 | return ERR_PTR(-ENODEV); | ||
1516 | } | 1517 | } |
1517 | 1518 | ||
1518 | static int regulator_resolve_supply(struct regulator_dev *rdev) | 1519 | static int regulator_resolve_supply(struct regulator_dev *rdev) |
@@ -1529,8 +1530,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) | |||
1529 | if (rdev->supply) | 1530 | if (rdev->supply) |
1530 | return 0; | 1531 | return 0; |
1531 | 1532 | ||
1532 | r = regulator_dev_lookup(dev, rdev->supply_name, &ret); | 1533 | r = regulator_dev_lookup(dev, rdev->supply_name); |
1533 | if (!r) { | 1534 | if (IS_ERR(r)) { |
1535 | ret = PTR_ERR(r); | ||
1536 | |||
1534 | if (ret == -ENODEV) { | 1537 | if (ret == -ENODEV) { |
1535 | /* | 1538 | /* |
1536 | * No supply was specified for this regulator and | 1539 | * No supply was specified for this regulator and |
@@ -1601,10 +1604,11 @@ struct regulator *_regulator_get(struct device *dev, const char *id, | |||
1601 | if (dev) | 1604 | if (dev) |
1602 | devname = dev_name(dev); | 1605 | devname = dev_name(dev); |
1603 | 1606 | ||
1604 | rdev = regulator_dev_lookup(dev, id, &ret); | 1607 | rdev = regulator_dev_lookup(dev, id); |
1605 | if (rdev) | 1608 | if (!IS_ERR(rdev)) |
1606 | goto found; | 1609 | goto found; |
1607 | 1610 | ||
1611 | ret = PTR_ERR(rdev); | ||
1608 | regulator = ERR_PTR(ret); | 1612 | regulator = ERR_PTR(ret); |
1609 | 1613 | ||
1610 | /* | 1614 | /* |