From patchwork Tue Mar 10 08:27:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5974511 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 EF7AF9F318 for ; Tue, 10 Mar 2015 08:28:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2CE2820353 for ; Tue, 10 Mar 2015 08:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AE0020375 for ; Tue, 10 Mar 2015 08:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752532AbbCJI2W (ORCPT ); Tue, 10 Mar 2015 04:28:22 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:36860 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752332AbbCJI2H (ORCPT ); Tue, 10 Mar 2015 04:28:07 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) 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 <0NKZ00525MDN6110@mailout1.w1.samsung.com>; Tue, 10 Mar 2015 08:32:11 +0000 (GMT) X-AuditID: cbfec7f5-b7fc86d0000066b7-60-54feaa7f1d01 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 55.00.26295.F7AAEF45; Tue, 10 Mar 2015 08:25:35 +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:05 +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 15/22] power_supply: Increment power supply use counter when obtaining references Date: Tue, 10 Mar 2015 09:27:19 +0100 Message-id: <1425976046-20973-16-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: H4sIAAAAAAAAAyWRa0iTcRjF/e+97FWcvHnrRa3QkGSQt4IeoqIv0R8iKPKTFbV0XmhT2dS0 IG1Qed3UZYRoeJm5JnmbZqaJ6GbNW17YKnVKzEJT8zZDNC2n337POYfnfDgM4V5P+jDxCcli WYJIEkC7kP07Hy3HM3Q7EaGZ1f6gHFzmgeZTLgmK7V8kFM0sEdAxsMmHqjFvyKkIhcLXagKG 607B88aD0F5aRcL8bBgMKhb4ML1uRND2fZGGZ39reFDTqULQZLNQ8G31DwVj70tpWMs3IMi2 l9DwxmDlQ81mHQmjXeW74cV/NFj7jDTUdswSMNA/SkHJggf051LQ354MHx6PEKBvKiZgo8FG nT+KtasheKqzh8SqujUKt5VY+fhHgZqP9VohbtJl03jS0kHj30NDfPzSdBXrNRnYmDdJ4rnC LRovdZpp3Gx+SmJlsw5d8Y50ORMtlsSnimUh5267xCleqVBSy4G0in/jVCb67JaDnBmOPcm1 9I1T++zNDU/V0w52Z6sRZ8kKykEuu6zkcZoe655Bsyc4fY2GdhierJHhNpdm+Y6DYEcRZ5sx 8R0pDzaG0+gMe29JNpCbqqtFDhawmBsb2eDt1x3mTL3qvYzzrm63j5P71Rc56+gKKkCCcuSk Q17ilKgk+Z1YaXiwXCSVpyTEBkclSpvQ/sjr71B17+luxDIowFXw9fpOhDslSpWnS7sRxxAB ngKjalcSRIvS74tlibdkKRKxvBvxGGefTPRFGB2TP6QsloRM1odPOBkq866tFAijsP1eR/iT VkX9A6O0oSzSYFove3S5kTU3508U/BycX5tuXThWOqVVvDiUbK5sZfLD1D1F2w83u6LPanVz N2QX8NuuS+OhafqRu1tHtgK9in1nRm6WZPm7pjMtUpuf77KQ0bhJ/IJM6gBSHicKExIyueg/ taEGQMICAAA= 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 */