power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate
authorHans de Goede <hdegoede@redhat.com>
Sun, 6 Aug 2017 16:23:52 +0000 (18:23 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.co.uk>
Wed, 9 Aug 2017 15:56:46 +0000 (17:56 +0200)
Commit 2848e039c562 ("power: supply: Make power_supply_am_i_supplied return
-ENODEV if there are no suppliers") was supposed to make
power_supply_am_i_supplied() return -ENODEV when there are no supplies
which supply the supply passed to it.

But instead it will only return -ENODEV when there are no supplies at
all as data->count++; is incremented on every call of the iterator, rather
then only when __power_supply_is_supplied_by returns true. This commit
fixes this.

Fixes: 2848e039c562 ("power: supply: Make power_supply_am_i_supplied ...")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
drivers/power/supply/power_supply_core.c

index 540d3e0aa0115e27005cc79f46b585d9d5c9fd21..0741fcef3b4482813655ed34a704ca49b708f095 100644 (file)
@@ -314,11 +314,12 @@ static int __power_supply_am_i_supplied(struct device *dev, void *_data)
        struct power_supply *epsy = dev_get_drvdata(dev);
        struct psy_am_i_supplied_data *data = _data;
 
-       data->count++;
-       if (__power_supply_is_supplied_by(epsy, data->psy))
+       if (__power_supply_is_supplied_by(epsy, data->psy)) {
+               data->count++;
                if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
                                        &ret))
                        return ret.intval;
+       }
 
        return 0;
 }