From patchwork Fri Jan 30 14:47:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5751311 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 68F59BF440 for ; Fri, 30 Jan 2015 14:54:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4BC420219 for ; Fri, 30 Jan 2015 14:54:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3821D201CE for ; Fri, 30 Jan 2015 14:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964816AbbA3Ox3 (ORCPT ); Fri, 30 Jan 2015 09:53:29 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:56343 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933002AbbA3Osm (ORCPT ); Fri, 30 Jan 2015 09:48:42 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NIZ000HOVZV2080@mailout3.w1.samsung.com>; Fri, 30 Jan 2015 14:52:43 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-5a-54cb99369828 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 7A.29.07834.6399BC45; Fri, 30 Jan 2015 14:46:14 +0000 (GMT) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NIZ00EV0VSES470@eusync2.samsung.com>; Fri, 30 Jan 2015 14:48:39 +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 , Russell King Cc: Thomas Gleixner , Pavel Machek , Kyungmin Park , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski Subject: [PATCH v3 13/20] power_supply: Increment power supply use counter when obtaining references Date: Fri, 30 Jan 2015 15:47:51 +0100 Message-id: <1422629278-12202-14-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1422629278-12202-1-git-send-email-k.kozlowski@samsung.com> References: <1422629278-12202-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyVRV0xTYRTm7x1tCSVXQLxA4gPRkEBYUeAEjeFJbzBxkhhNHBUqkFDAFhAk AoI8sMpUAZlpsezSokagDFGqWJasIHsmyJCtQABt4e0733w4HMykBbfk+AeGCESB/ABr0hDX Hnztt3fN0Xo5FadYgKRzlQXKbAUBsm9JOMTuL+CQMbuCgbpjlw3SPnNILHaC9LJMDOKkChJ6 qt3glfIEvF0rJKEhT4rD4rwzdMYusWFiqw1B3dQyCVl7chbIm1IRqGYGCfi5/oeAvvo8EjZS viBI2MwlYaSPBwndxQjku9U49LYU6QLL/0gY+95GQoV6HoMObS8BuUumoE0iQNsQAo3xPzCo Vb3EYLtmhvCwYV7EJZNM6bojM970GWdSqzcIpi53jM2srt1j5tIy2UxtqS0zuyAnGFV5AsmM DqpJ5ndXF5spaL/ONOdX6gyyaKYteRS/ZnnH8LyPIMA/TCByvPDA0O9Nzg4R/P5YeIskHotB 3caJiMuhqbN0R18V+wib0z3jClKPTagSRA/H3khEhjosYdFDE/GEXiCpM3StXEbqBTNqmUtr JGpcf2DUCKLr1GUsvcuUekR35G8dVuHUaTr5kz7N4fAoht4YjDpaO0m3azIPS7k6umZ+mjha vkSnDmSTaYhXhAzK0XFBqHew+KGv0NlBzBeKQwN9HbyDhCp09PXNj0iqcW9FFAdZG/GG+Fov E4IfJo4QtiKag1mb8bIydBTPhx/xVCAKui8KDRCIWxGLw7WMQZ4TCqsqXv1w7Yd6icjNb795 p2bVpXLbw3hxwHMjXR1ZovarjPJf+6XYK3C8qpy+bDpP54f/zXtmY2G0wrIzaJyzq3iedXCq X7n0z5V7ccq+K+zJiM1k5N3bqtZU5TsXu7lb3PL6x9NQ1i/TFFruSMOvWJ1T3XxNTrpGr8W1 2bpb42I/vrMtJhLz/wNRYXIK0wIAAA== 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 95aeae44c34a..acad7e87f754 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 */