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: 5899371 Return-Path: X-Original-To: patchwork-linux-arm@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 061539F373 for ; Fri, 27 Feb 2015 08:32:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32654201CE for ; Fri, 27 Feb 2015 08:32:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D69F201BC for ; Fri, 27 Feb 2015 08:32:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YRGEo-000483-Jo; Fri, 27 Feb 2015 08:25:34 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YRGAa-0000Ay-Aj for linux-arm-kernel@lists.infradead.org; Fri, 27 Feb 2015 08:21:20 +0000 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> for linux-arm-kernel@lists.infradead.org; Fri, 27 Feb 2015 08:24:53 +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 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== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150227_002112_603478_2B65FF16 X-CRM114-Status: GOOD ( 11.31 ) X-Spam-Score: -5.0 (-----) Cc: Krzysztof Kozlowski , Thomas Gleixner , Kyungmin Park , Pavel Machek , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 */