aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-09-04 08:01:30 -0400
committerSebastian Reichel <sre@kernel.org>2014-09-16 05:01:33 -0400
commit585b008743b5a14d93e3d506729c73978edc8da7 (patch)
treef9aebdaa291df8651f5733ad553039c338b36e40
parentf5b89affe2b2e6a6092f4228baf08a6dd59bfc61 (diff)
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: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r--drivers/power/power_supply_core.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index ab1cf8bcbefb..55140ebf914c 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -161,9 +161,9 @@ static int __power_supply_find_supply_from_node(struct device *dev,
161 struct device_node *np = data; 161 struct device_node *np = data;
162 struct power_supply *epsy = dev_get_drvdata(dev); 162 struct power_supply *epsy = dev_get_drvdata(dev);
163 163
164 /* return error breaks out of class_for_each_device loop */ 164 /* returning non-zero breaks out of class_for_each_device loop */
165 if (epsy->of_node == np) 165 if (epsy->of_node == np)
166 return -EINVAL; 166 return 1;
167 167
168 return 0; 168 return 0;
169} 169}
@@ -186,15 +186,19 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)
186 return -EPROBE_DEFER; 186 return -EPROBE_DEFER;
187 187
188 /* 188 /*
189 * We have to treat the return value as inverted, because if 189 * class_for_each_device() either returns its own errors or values
190 * we return error on not found, then it won't continue looking. 190 * returned by __power_supply_find_supply_from_node().
191 * So we trick it by returning error on success to stop looking 191 *
192 * once the matching device is found. 192 * __power_supply_find_supply_from_node() will return 0 (no match)
193 * or 1 (match).
194 *
195 * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
196 * it returned 0, or error as returned by it.
193 */ 197 */
194 error = class_for_each_device(power_supply_class, NULL, supply_node, 198 error = class_for_each_device(power_supply_class, NULL, supply_node,
195 __power_supply_find_supply_from_node); 199 __power_supply_find_supply_from_node);
196 200
197 return error ? 0 : -EPROBE_DEFER; 201 return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
198} 202}
199 203
200static int power_supply_check_supplies(struct power_supply *psy) 204static int power_supply_check_supplies(struct power_supply *psy)