Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751984AbdHFMgg (ORCPT ); Sun, 6 Aug 2017 08:36:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42164 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbdHFMgc (ORCPT ); Sun, 6 Aug 2017 08:36:32 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61D79356CC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=hdegoede@redhat.com From: Hans de Goede To: Darren Hart , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , Greg Kroah-Hartman , Guenter Roeck , Heikki Krogerus Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Liam Breck , Tony Lindgren , linux-pm@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH 11/18] power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate Date: Sun, 6 Aug 2017 14:35:48 +0200 Message-Id: <20170806123555.5124-12-hdegoede@redhat.com> In-Reply-To: <20170806123555.5124-1-hdegoede@redhat.com> References: <20170806123555.5124-1-hdegoede@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 06 Aug 2017 12:36:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1409 Lines: 37 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 --- drivers/power/supply/power_supply_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 540d3e0aa011..0741fcef3b44 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -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; } -- 2.13.3