From patchwork Tue Mar 10 08:27:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5974911 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A7DC9BF440 for ; Tue, 10 Mar 2015 08:32:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9D4520251 for ; Tue, 10 Mar 2015 08:32:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7A8C2024F for ; Tue, 10 Mar 2015 08:32:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752871AbbCJIbV (ORCPT ); Tue, 10 Mar 2015 04:31:21 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:31254 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446AbbCJI2P (ORCPT ); Tue, 10 Mar 2015 04:28:15 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NKZ0024BMDH6V10@mailout4.w1.samsung.com>; Tue, 10 Mar 2015 08:32:05 +0000 (GMT) X-AuditID: cbfec7f5-b7fc86d0000066b7-66-54feaa805602 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 58.00.26295.08AAEF45; Tue, 10 Mar 2015 08:25:36 +0000 (GMT) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NKZ0033KM64IB70@eusync4.samsung.com>; Tue, 10 Mar 2015 08:28:06 +0000 (GMT) From: Krzysztof Kozlowski To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , "Rafael J. Wysocki" , Len Brown , Jiri Kosina , David Herrmann , Cezary Jackiewicz , Darren Hart , Support Opensource , Milo Kim , Linus Walleij , Samuel Ortiz , Lee Jones , linux-arm-kernel@lists.infradead.org, Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-input@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@opensource.wolfsonmicro.com, ac100@lists.launchpad.net, linux-tegra@vger.kernel.org, devel@driverdev.osuosl.org Cc: Thomas Gleixner , Pavel Machek , Kyungmin Park , Marek Szyprowski , Krzysztof Kozlowski Subject: [PATCH v6 16/22] power_supply: charger-manager: Decrement the power supply's device reference counter Date: Tue, 10 Mar 2015 09:27:20 +0100 Message-id: <1425976046-20973-17-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1425976046-20973-1-git-send-email-k.kozlowski@samsung.com> References: <1425976046-20973-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAy2RW0iTcRjG/e/79n1zNviYZh9eCC280TybvtlJKuh/EZQgEgblckOFeWBT ybrIRlGepmZqiYShpmmeNiPP2HSaTc3N1BQ1bQbqPJSHzJWa0+6e53l/L8/FwyOEdaQTLzo2 QSqPFctEFJ/U7/SMuKdU7oR4NX/yBVX/Dw6UfkgnQbm9QMKT2RUCWvssNJQMOULaSy/IeZ1L wGBNAOTXH4GWohISzHPe0K9cpOHrhg5B08wSBU//lnOgvD0Lgdo0woWx1V9cGGouomAtswtB 6nohBdVdkzSUW2pIMHYU78FLuxRMftRRUNU6R0Cf3siFwkV70KdzQd+SAG0PDQRo1HkE/K4z cYOO4YpVTzzV3knirJo1Lm4qnKTx9+xcGmsqXLG6MpXCEyOtFF4eGKDxi95grCm9h3UZEySe z/lD4ZX2YQo3DD8isaqhEl11DOOflkhl0UlSuefZcH6UueozGW88cTvvQSonBSnd0pAtj2X8 2Px3BuJAO7KDU7VUGuLzhEwZYhv7Mv8bFYf9Zl6irBTF+LKa8tL9gwOj47GWlTnaagjGiFjT bC9tpeyZeHa6Q7v/QTIubG7x6n6HgMHs9mInddDnzPZ253Kt2nYvX18fJ61ayFxiJ40/UTYS FCObSnRYmhgRr7gVGePjoRDHKBJjIz0i4mLU6GDljUZU1h2oRQwPiQ4JvlzfCRFyxUmK5Bgt YnmEyEGgy9qLBBJx8h2pPO6mPFEmVWgRh2frlIJc0649nrEryr8cNWY65RPUrz5ZZi7wd7kw 3fDKnzDx3weTb8K6VaKM2l06YKtnW2qws7lfwvcO9dz0nhJvLoQqZaOGhfqMah9n/bkR1ZXz pq15erSgnrkRFHY0OeiZJS7dhxMsaZN1BOYLQKu4eDzc7/nbM3fHtZrW5dfubhIRqYgSe7sS coX4H5CmWAPDAgAA Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use power_supply_put() to decrement the power supply's device reference counter. Signed-off-by: Krzysztof Kozlowski Acked-by: Pavel Machek Reviewed-by: Bartlomiej Zolnierkiewicz Reviewed-by: Sebastian Reichel --- drivers/power/charger-manager.c | 70 +++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 5c47409c6889..e23b7ba2cbd2 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c @@ -107,6 +107,7 @@ static bool is_batt_present(struct charger_manager *cm) &val); if (ret == 0 && val.intval) present = true; + power_supply_put(psy); break; case CM_CHARGER_STAT: for (i = 0; cm->desc->psy_charger_stat[i]; i++) { @@ -120,6 +121,7 @@ static bool is_batt_present(struct charger_manager *cm) ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_PRESENT, &val); + power_supply_put(psy); if (ret == 0 && val.intval) { present = true; break; @@ -157,6 +159,7 @@ static bool is_ext_pwr_online(struct charger_manager *cm) ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val); + power_supply_put(psy); if (ret == 0 && val.intval) { online = true; break; @@ -186,6 +189,7 @@ static int get_batt_uV(struct charger_manager *cm, int *uV) ret = power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_VOLTAGE_NOW, &val); + power_supply_put(fuel_gauge); if (ret) return ret; @@ -229,10 +233,13 @@ static bool is_charging(struct charger_manager *cm) if (ret) { dev_warn(cm->dev, "Cannot read ONLINE value from %s\n", cm->desc->psy_charger_stat[i]); + power_supply_put(psy); continue; } - if (val.intval == 0) + if (val.intval == 0) { + power_supply_put(psy); continue; + } /* * 3. The charger should not be FULL, DISCHARGING, @@ -240,6 +247,7 @@ static bool is_charging(struct charger_manager *cm) */ ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_STATUS, &val); + power_supply_put(psy); if (ret) { dev_warn(cm->dev, "Cannot read STATUS value from %s\n", cm->desc->psy_charger_stat[i]); @@ -267,6 +275,7 @@ static bool is_full_charged(struct charger_manager *cm) struct charger_desc *desc = cm->desc; union power_supply_propval val; struct power_supply *fuel_gauge; + bool is_full = false; int ret = 0; int uV; @@ -284,15 +293,19 @@ static bool is_full_charged(struct charger_manager *cm) /* Not full if capacity of fuel gauge isn't full */ ret = power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CHARGE_FULL, &val); - if (!ret && val.intval > desc->fullbatt_full_capacity) - return true; + if (!ret && val.intval > desc->fullbatt_full_capacity) { + is_full = true; + goto out; + } } /* Full, if it's over the fullbatt voltage */ if (desc->fullbatt_uV > 0) { ret = get_batt_uV(cm, &uV); - if (!ret && uV >= desc->fullbatt_uV) - return true; + if (!ret && uV >= desc->fullbatt_uV) { + is_full = true; + goto out; + } } /* Full, if the capacity is more than fullbatt_soc */ @@ -301,11 +314,15 @@ static bool is_full_charged(struct charger_manager *cm) ret = power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CAPACITY, &val); - if (!ret && val.intval >= desc->fullbatt_soc) - return true; + if (!ret && val.intval >= desc->fullbatt_soc) { + is_full = true; + goto out; + } } - return false; +out: + power_supply_put(fuel_gauge); + return is_full; } /** @@ -578,14 +595,18 @@ static int cm_get_battery_temperature_by_psy(struct charger_manager *cm, int *temp) { struct power_supply *fuel_gauge; + int ret; fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge); if (!fuel_gauge) return -ENODEV; - return power_supply_get_property(fuel_gauge, + ret = power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_TEMP, (union power_supply_propval *)temp); + power_supply_put(fuel_gauge); + + return ret; } static int cm_get_battery_temperature(struct charger_manager *cm, @@ -866,7 +887,7 @@ static int charger_get_property(struct power_supply *psy, { struct charger_manager *cm = power_supply_get_drvdata(psy); struct charger_desc *desc = cm->desc; - struct power_supply *fuel_gauge; + struct power_supply *fuel_gauge = NULL; int ret = 0; int uV; @@ -909,18 +930,18 @@ static int charger_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_TEMP_AMBIENT: return cm_get_battery_temperature(cm, &val->intval); case POWER_SUPPLY_PROP_CAPACITY: - fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge); - if (!fuel_gauge) { - ret = -ENODEV; - break; - } - if (!is_batt_present(cm)) { /* There is no battery. Assume 100% */ val->intval = 100; break; } + fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge); + if (!fuel_gauge) { + ret = -ENODEV; + break; + } + ret = power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CAPACITY, val); if (ret) @@ -995,6 +1016,8 @@ static int charger_get_property(struct power_supply *psy, default: return -EINVAL; } + if (fuel_gauge) + power_supply_put(fuel_gauge); return ret; } @@ -1676,13 +1699,7 @@ static int charger_manager_probe(struct platform_device *pdev) desc->psy_charger_stat[i]); return -ENODEV; } - } - - fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge); - if (!fuel_gauge) { - dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", - desc->psy_fuel_gauge); - return -ENODEV; + power_supply_put(psy); } if (desc->polling_interval_ms == 0 || @@ -1722,6 +1739,12 @@ static int charger_manager_probe(struct platform_device *pdev) cm->charger_psy_desc.num_properties = psy_default.num_properties; /* Find which optional psy-properties are available */ + fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge); + if (!fuel_gauge) { + dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", + desc->psy_fuel_gauge); + return -ENODEV; + } if (!power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = @@ -1741,6 +1764,7 @@ static int charger_manager_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to initialize thermal data\n"); cm->desc->measure_battery_temp = false; } + power_supply_put(fuel_gauge); INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);