Commit 585b0087 authored by Viresh Kumar's avatar Viresh Kumar Committed by Sebastian Reichel

power-supply: Don't return -EINVAL from __power_supply_find_supply_from_node()

We need to stop 'class_for_each_device' loop when a supply matches with the
of-node. In order to achieve this we currently return -EINVAL from
__power_supply_populate_supplied_from() on successful match.

class_for_each_device() is free to return similar errors in other cases as well
and so the choice of return value here isn't particularly great.

This commit isn't removing the Hack but making it more elegant by returning '1'
instead.

Also power_supply_find_supply_from_node() can return errors other than
-EPROBE_DEFER now if class_for_each_device() fails.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent f5b89aff
...@@ -161,9 +161,9 @@ static int __power_supply_find_supply_from_node(struct device *dev, ...@@ -161,9 +161,9 @@ static int __power_supply_find_supply_from_node(struct device *dev,
struct device_node *np = data; struct device_node *np = data;
struct power_supply *epsy = dev_get_drvdata(dev); struct power_supply *epsy = dev_get_drvdata(dev);
/* return error breaks out of class_for_each_device loop */ /* returning non-zero breaks out of class_for_each_device loop */
if (epsy->of_node == np) if (epsy->of_node == np)
return -EINVAL; return 1;
return 0; return 0;
} }
...@@ -186,15 +186,19 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node) ...@@ -186,15 +186,19 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
return -EPROBE_DEFER; return -EPROBE_DEFER;
/* /*
* We have to treat the return value as inverted, because if * class_for_each_device() either returns its own errors or values
* we return error on not found, then it won't continue looking. * returned by __power_supply_find_supply_from_node().
* So we trick it by returning error on success to stop looking *
* once the matching device is found. * __power_supply_find_supply_from_node() will return 0 (no match)
* or 1 (match).
*
* We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
* it returned 0, or error as returned by it.
*/ */
error = class_for_each_device(power_supply_class, NULL, supply_node, error = class_for_each_device(power_supply_class, NULL, supply_node,
__power_supply_find_supply_from_node); __power_supply_find_supply_from_node);
return error ? 0 : -EPROBE_DEFER; return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
} }
static int power_supply_check_supplies(struct power_supply *psy) static int power_supply_check_supplies(struct power_supply *psy)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment