From patchwork Tue Sep 23 18:44:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 4958981 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D892B9F3DF for ; Tue, 23 Sep 2014 18:48:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEAC920265 for ; Tue, 23 Sep 2014 18:48:02 +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 456062015A for ; Tue, 23 Sep 2014 18:47:57 +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 1XWV5y-0005F7-EJ; Tue, 23 Sep 2014 18:45:50 +0000 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWV5L-0003YO-9N for linux-arm-kernel@lists.infradead.org; Tue, 23 Sep 2014 18:45:12 +0000 Received: by mail-wi0-f176.google.com with SMTP id fb4so5520299wid.3 for ; Tue, 23 Sep 2014 11:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zs7ghnvz+H09oXW2SImvHx/c9wN+sfLafPmLSBjhWMw=; b=BNSMGu1canid/NCEmd9Dt9BPXzsjk0WBaFxpJTC6kr2AVnn4TxqJLv8rGOXnTyiNib /E/0bbjQeRFJloYKP3Z8jUPgO5cx3NOnB10Eyk+eGiN+f5HTCrXMArDGNbnFd9DQhjSD dAY6UrN0/wjDXft57DPkbtT/NZgwDxxqet+eWONIkNC6dpdz6hVE2tQku/neKW8Ftauu u9o9b9955G3EYblGcl+IPOYd4Sy67h9e3YiCWYZzHZ0qQuSgesN+cNiY4RwwQKhW3CGC DNdy4mQpbJLXBI50XkQjh7LIOkVtNblPv4xPoq3ep+hPcIFs85JsOwqR1LmpYq+LPYUO EkJQ== X-Received: by 10.194.23.69 with SMTP id k5mr1705690wjf.31.1411497889313; Tue, 23 Sep 2014 11:44:49 -0700 (PDT) Received: from cizrna.lan (37-48-33-192.tmcz.cz. [37.48.33.192]) by mx.google.com with ESMTPSA id pn5sm16871650wjc.4.2014.09.23.11.44.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Sep 2014 11:44:48 -0700 (PDT) From: Tomeu Vizoso To: Mike Turquette Subject: [PATCH v13 6/9] clk: Warn of unbalanced clk_prepare() calls Date: Tue, 23 Sep 2014 20:44:14 +0200 Message-Id: <1411497857-24726-4-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1411497857-24726-1-git-send-email-tomeu.vizoso@collabora.com> References: <1411497613-24049-1-git-send-email-tomeu.vizoso@collabora.com> <1411497857-24726-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140923_114511_500060_1F52B921 X-CRM114-Status: GOOD ( 14.93 ) X-Spam-Score: -0.7 (/) Cc: Russell King , Tomeu Vizoso , Stephen Warren , Peter De Schrijver , linux-kernel@vger.kernel.org, tomasz.figa@gmail.com, rabin@rab.in, Thierry Reding , Javier Martinez Canillas , linux-arm-kernel@lists.infradead.org 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=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,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 The warning will display the clock user that is trying to unprepare the clock, and the location of the last unprepare call. Signed-off-by: Tomeu Vizoso --- v8: * Patch added --- drivers/clk/clk.c | 22 ++++++++++++++++++++-- include/linux/clk-private.h | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 11ab923..bfb4672 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -878,7 +878,17 @@ void clk_unprepare(struct clk *clk_user) if (IS_ERR_OR_NULL(clk_user)) return; - clk_provider_unprepare(clk_to_clk_core(clk_user)); + clk_prepare_lock(); + if (!WARN(clk_user->prepare_count == 0, + "incorrect unprepare clk dev %s con %s last caller of unprepare %pF\n", + clk_user->dev_id, clk_user->con_id, clk_user->last_unprepare)) { + + clk_user->last_unprepare = __builtin_return_address(0); + clk_user->prepare_count--; + + __clk_unprepare(clk_to_clk_core(clk_user)); + } + clk_prepare_unlock(); } EXPORT_SYMBOL_GPL(clk_unprepare); @@ -934,10 +944,18 @@ EXPORT_SYMBOL_GPL(clk_provider_prepare); */ int clk_prepare(struct clk *clk_user) { + int ret; + if (!clk_user) return 0; - return clk_provider_prepare(clk_to_clk_core(clk_user)); + clk_prepare_lock(); + ret = __clk_prepare(clk_to_clk_core(clk_user)); + if (!ret) + clk_user->prepare_count++; + clk_prepare_unlock(); + + return ret; } EXPORT_SYMBOL_GPL(clk_prepare); diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h index 8126046..cf93bde 100644 --- a/include/linux/clk-private.h +++ b/include/linux/clk-private.h @@ -64,6 +64,9 @@ struct clk { unsigned int enable_count; void *last_disable; + unsigned int prepare_count; + void *last_unprepare; + unsigned long floor_constraint; unsigned long ceiling_constraint; struct hlist_node child_node;