From patchwork Thu Oct 1 19:05:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 7310861 Return-Path: X-Original-To: patchwork-linux-pm@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 419A8BEEA4 for ; Thu, 1 Oct 2015 19:05:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E527207A4 for ; Thu, 1 Oct 2015 19:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E11F72079C for ; Thu, 1 Oct 2015 19:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753421AbbJATFO (ORCPT ); Thu, 1 Oct 2015 15:05:14 -0400 Received: from gloria.sntech.de ([95.129.55.99]:58636 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751705AbbJATFN (ORCPT ); Thu, 1 Oct 2015 15:05:13 -0400 Received: from ip5f5b95ad.dynamic.kabel-deutschland.de ([95.91.149.173] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1ZhjAE-0005Nf-Gk; Thu, 01 Oct 2015 21:05:10 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: "Rafael J. Wysocki" , Pavel Machek Cc: Stephen Boyd , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PM / clk: Do not __clk_get passed in clock-references Date: Thu, 01 Oct 2015 21:05:09 +0200 Message-ID: <4072102.uMAk2BYxyL@diego> User-Agent: KMail/4.14.10 (Linux/4.1.0-2-amd64; KDE/4.14.10; x86_64; ; ) MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 From: Stephen Boyd Clock references are on a per-user basis now, so they are not supposed to be refcounted by itself anymore. Therefore multiple cascaded get and put calls will fail. When a clock reference gets passed into pm_clk_add_clk we can assume that the pm clock handling will take control of the clock reference, so after this functions returns the caller should've given up control of that handle. So remove the additional call to __clk_get() in __pm_clk_add(). The only current user of pm_clk_add_clk is drivers/clk/shmobile/clk-mstp.c which already follows this paradigm by only getting the clock but not puting it after passing the reference into pm_clk_add_clk. In the error case the caller is expected to clean up the clock, as it may very well try to do something different if pm_clk_add_clk() fails. Signed-off-by: Stephen Boyd [add commit-message] Signed-off-by: Heiko Stuebner Acked-by: Rafael J. Wysocki --- Hi Rafael, Pavel, if that looks acceptable to you, it would be cool if you could ack the patch and allow me to put it in front of [0] or alternatively provide a stable-branch I could include. Thanks Heiko [0] https://git.kernel.org/cgit/linux/kernel/git/mmind/linux-rockchip.git/commit/?h=v4.4-armsoc/drivers drivers/base/power/clock_ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c index 652b5a3..6ce7693 100644 --- a/drivers/base/power/clock_ops.c +++ b/drivers/base/power/clock_ops.c @@ -93,7 +93,7 @@ static int __pm_clk_add(struct device *dev, const char *con_id, return -ENOMEM; } } else { - if (IS_ERR(clk) || !__clk_get(clk)) { + if (IS_ERR(clk)) { kfree(ce); return -ENOENT; } @@ -127,7 +127,9 @@ int pm_clk_add(struct device *dev, const char *con_id) * @clk: Clock pointer * * Add the clock to the list of clocks used for the power management of @dev. - * It will increment refcount on clock pointer, use clk_put() on it when done. + * The power-management code will take control of the clock reference, so + * callers should not call clk_put() on @clk after this function sucessfully + * returned. */ int pm_clk_add_clk(struct device *dev, struct clk *clk) {