power_supply: Fix unbalanced the power supplies

If a driver invokes multiple power_supply_register(), the each supply
will not be saved in the supplied_from[] with the correct index.

supplied_from[0] = "dc"
num_supplies = 1;

supplied_from[0] = "usb"
num_supplies = 2;

supplied_from[0] = "battery"
num_supplies = 3;
...

It results in NPE when iterating the supplied_from[] with num_supplies on
__power_supply_is_supplied_by()

Bug: 63785418
Change-Id: Ifd14ca7c6e2df247e1090e4fa8d8c66bd2912180
Signed-off-by; Devin Kim <dojip.kim@lge.com>
Signed-off-by: Steve Pfetsch <spfetsch@google.com>
This commit is contained in:
jonghyun26.kim 2017-07-24 15:39:48 -07:00 committed by Timi
parent 91730df4a8
commit 927bce4ae9

View file

@ -166,8 +166,8 @@ static int __power_supply_populate_supplied_from(struct device *dev,
if (np == epsy->of_node) { if (np == epsy->of_node) {
dev_info(&psy->dev, "%s: Found supply : %s\n", dev_info(&psy->dev, "%s: Found supply : %s\n",
psy->desc->name, epsy->desc->name); psy->desc->name, epsy->desc->name);
psy->supplied_from[i-1] = (char *)epsy->desc->name; psy->supplied_from[psy->num_supplies++] =
psy->num_supplies++; (char *)epsy->desc->name;
of_node_put(np); of_node_put(np);
break; break;
} }