From patchwork Mon Feb 23 11:47:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5864411 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 4A9869F169 for ; Mon, 23 Feb 2015 11:50:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DE152061F for ; Mon, 23 Feb 2015 11:50:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8499820610 for ; Mon, 23 Feb 2015 11:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbbBWLs2 (ORCPT ); Mon, 23 Feb 2015 06:48:28 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:55356 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbbBWLsS (ORCPT ); Mon, 23 Feb 2015 06:48:18 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NK800IKL3N4XAA0@mailout2.w1.samsung.com>; Mon, 23 Feb 2015 11:52:17 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-12-54eb12eec2e9 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 5E.5A.07834.EE21BE45; Mon, 23 Feb 2015 11:45:50 +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 <0NK8001843FJ0A90@eusync2.samsung.com>; Mon, 23 Feb 2015 11:48:15 +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 v4 13/20] power_supply: Increment power supply use counter when obtaining references Date: Mon, 23 Feb 2015 12:47:34 +0100 Message-id: <1424692061-30624-14-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1424692061-30624-1-git-send-email-k.kozlowski@samsung.com> References: <1424692061-30624-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyWRa0yScRTG+/NeYVGvpPZWW2tYbbkyWa3OWsuWq/61PtiyL65pqGQtMINg 2dqyXCslssIuMzMNgrLExGpeyNTEMsRbza2L3aCthExFW3YzkG+/85znOc+HwxISBzmX3Zd9 SKHOliultIh0/Xv6ctmQxJccf98SAWfdwwIwP9OTcOLvIAkXvN8JcHT+YsD0IhoKK+Lh/G0j Afmmahp6bKvhUs1ssIxcp6Gx1ESC74sM3Cf8DLwfdyKo//iNhuI/VgFYm4oQ2D39FLwa/UHB i4ZSGgKGNgQFYyU0VLUNMFDQXYHA+stGQl9zeTDxbZKGgedOGu44vhDQ6eqjoMQ/C1x6ClyN h+DRyV4Cau0XCfh5z0OtX4xvjS7H75qekLjIFqBwfckAg4dHUvHnc0YG196Kxd5BK4XtlQU0 ftvvoPFQVxeDyzq248fX7gYN5mPYeeYtib+e/00nzUkRrc1UKPfpFOrl63aL9pb6n9E5DyIO X5l0Mnmoe0YhErI8t5L3DdvpMEfzPe+qgyxiJdxNxHfbnExoIeHOCvi6IW2IaW4FX2s1T5ki uXYh31JlEIQGgutDvMfbMZWYxe3hCwNjU2dJbhEfCNipEIs5zBtPOZhw3Xy+o90Y1FlWGNTf P9SFyzbzhppidA6Jy9G0ShSl0GbkaNKzVLI4jVyl0WZnxWUcUNlR+ONjdcjUvqYVcSySThd/ 0A0mSyi5TpOrakU8S0gjxfMmgpI4U557RKE+kKbWKhWaViRghXPzUExUylJ/08EZ7q0TLe44 eVH6ks6Z0tx/afrtp6eJt8SKA20J/onX4sQnuF/nily4jdzRYHt1vPeY7HLVpw1logZ9vOtG r39XT545KjWtzOLJSjrqbUnJSYjelFhz0dd1dcH473rlm5Fd8wP7N+ZnWJKwMH1y7ZiweFWM X7Wz2ZAoJTV75bJYQq2R/wcci1BFzwIAAA== 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 a94f8c9d5e1e..819430a0bfa6 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 */