From patchwork Fri Feb 27 08:19:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5898851 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AF3EF9F373 for ; Fri, 27 Feb 2015 08:25:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB1DA201DD for ; Fri, 27 Feb 2015 08:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B8C32020E for ; Fri, 27 Feb 2015 08:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754517AbbB0IYA (ORCPT ); Fri, 27 Feb 2015 03:24:00 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:46628 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754672AbbB0IUu (ORCPT ); Fri, 27 Feb 2015 03:20:50 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NKF00CFJ8PHWO70@mailout1.w1.samsung.com>; Fri, 27 Feb 2015 08:24:54 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-33-54f0284d9cf0 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 33.BD.07834.D4820F45; Fri, 27 Feb 2015 08:18:22 +0000 (GMT) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NKF007VV8HM7X70@eusync1.samsung.com>; Fri, 27 Feb 2015 08:20:47 +0000 (GMT) From: Krzysztof Kozlowski To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Len Brown , Jiri Kosina , David Herrmann , Cezary Jackiewicz , Darren Hart , Support Opensource , Milo Kim , Julian Andres Klode , Marc Dietrich , Greg Kroah-Hartman , 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, 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 Cc: Thomas Gleixner , Pavel Machek , Kyungmin Park , Marek Szyprowski , Krzysztof Kozlowski Subject: [PATCH v5 13/20] power_supply: Increment power supply use counter when obtaining references Date: Fri, 27 Feb 2015 09:19:54 +0100 Message-id: <1425025201-15926-14-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1425025201-15926-1-git-send-email-k.kozlowski@samsung.com> References: <1425025201-15926-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyWRaUjTcRjH++1/bI4Wf+f1z6AXwySEpuugx8ryheQ/ikiwoKBy6TzAi01F LXAoEV7zTGtpOabOPGZNA81pZWqteU4QEw9EM/Oct2lqzr37PM/z+fJ98XAwvh535oRFxkik keJwAcnFjbvf+k/dPGn29yhwBkWXmQWl39NxSN6ZwSF3chEDfecWG9T9jpCm8oCct3kYpKhr SejVnoeC905QvvSGhKYiNQ6z0yLoSp5jw9haO4LG8XkS8v9pWKBpyUKgmxgg4OfyOgH9H4tI WMlsQ5C6qiShpm2EDak9KgSaLS0Ops8l+4n5PRJGfrSTUKWfxqDTaCJAOWcHxnQCjE0x0Py0 D4M63XMMNt9NEN6uTMWyOzPa8hVnsrQrBNOoHGEz5qUHzK/sPDZTV+HGTM5oCEZXmUoywwN6 klno7mYzrw1+zKfi6n2hNIlpzxjGmT852+Sto/e4l4Ik4WFxEqn75QBuaHJ5For+YBuv2hsi 5KjnSBqy4dDUWXqoZxuzsiPdO1pLWphPlSF6PT82DXH3WcGid2cGDySSOkPXaUpJy8Ge6rCh v9RksiwDRpkQPTFpYFssOyqYVhqnDhI4dYJu0OXiFuZRDJ06vENY647Tho68A7bZ3y/svGRb q33pWtUGyka8EnSoEjlIYgOjZY9CIkRCmThCFhsZIgyMitAh68dXG5C640IrojhIcJjnbWv2 5xPiOFlCRCuiOZjAnofGF/35vCBxQqJEGvVQGhsukbUiFsfGWY4ctO19d7S7wkIzZ77L54aL y6C56Hqhz5hId7HK0+v27AwvfF0uUAykO07/DnilWEwpbl4ZMKhyROc2y3QZFOfYspNXF/eu uEG+MWW6llivFvouPnY4/bfecTTwfppaOeLWaareSbriWv3s6vyT8uD4tawXcqGdstLTuV/v 1zMnwGWhYpEbJpWJ/wNYfZSIzwIAAA== 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 Increment the power_supply.use_cnt usage counter on: - power_supply_get_by_phandle() - power_supply_get_by_name() and decrement it on power_supply_put() call. This helps tracking of valid usage of power supply instance by consumers. The usage counter itself also allows safe calling of power_supply_get_property-like functions even when driver unregisters this power supply. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bartlomiej Zolnierkiewicz --- drivers/power/power_supply_core.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index b4ec14683b7f..2ed4a4a6b3c5 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -349,10 +349,16 @@ static int power_supply_match_device_by_name(struct device *dev, const void *dat */ struct power_supply *power_supply_get_by_name(const char *name) { + struct power_supply *psy = NULL; struct device *dev = class_find_device(power_supply_class, NULL, name, power_supply_match_device_by_name); - return dev ? dev_get_drvdata(dev) : NULL; + if (dev) { + psy = dev_get_drvdata(dev); + atomic_inc(&psy->use_cnt); + } + + return psy; } EXPORT_SYMBOL_GPL(power_supply_get_by_name); @@ -367,6 +373,7 @@ void power_supply_put(struct power_supply *psy) { might_sleep(); + atomic_dec(&psy->use_cnt); put_device(&psy->dev); } EXPORT_SYMBOL_GPL(power_supply_put); @@ -393,6 +400,7 @@ struct power_supply *power_supply_get_by_phandle(struct device_node *np, const char *property) { struct device_node *power_supply_np; + struct power_supply *psy = NULL; struct device *dev; power_supply_np = of_parse_phandle(np, property, 0); @@ -404,7 +412,12 @@ struct power_supply *power_supply_get_by_phandle(struct device_node *np, of_node_put(power_supply_np); - return dev ? dev_get_drvdata(dev) : NULL; + if (dev) { + psy = dev_get_drvdata(dev); + atomic_inc(&psy->use_cnt); + } + + return psy; } EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); #endif /* CONFIG_OF */