From patchwork Sat Dec 5 06:17:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 7774881 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3B8E99F39B for ; Sat, 5 Dec 2015 06:21:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40FED20601 for ; Sat, 5 Dec 2015 06:21:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A174C205FE for ; Sat, 5 Dec 2015 06:21:55 +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 1a56BG-0003iU-Qa; Sat, 05 Dec 2015 06:18:50 +0000 Received: from conuserg009.nifty.com ([202.248.44.35] helo=conuserg009-v.nifty.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a56BC-0003fy-K2 for linux-arm-kernel@lists.infradead.org; Sat, 05 Dec 2015 06:18:47 +0000 Received: from grover.sesame (FL1-203-136-65-164.osk.mesh.ad.jp [203.136.65.164]) (authenticated) by conuserg009-v.nifty.com with ESMTP id tB56HwRs021501; Sat, 5 Dec 2015 15:18:01 +0900 X-Nifty-SrcIP: [203.136.65.164] From: Masahiro Yamada To: linux-clk@vger.kernel.org Subject: [PATCH] clk: let clk_disable() return immediately if clk is NULL or error Date: Sat, 5 Dec 2015 15:17:56 +0900 Message-Id: <1449296276-32208-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151204_221846_901985_AB101A51 X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: 1.4 (+) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, linux-sh@vger.kernel.org, Masahiro Yamada , Greg Ungerer , Roland Stigge , Russell King , Dmitry Eremin-Solenikov , Magnus Damm , Geert Uytterhoeven , Wan ZongShun , Steven Miao , Hauke Mehrtens , adi-buildroot-devel@lists.sourceforge.net, Haojian Zhuang , linux-m68k@lists.linux-m68k.org, Simon Horman , linux-arm-kernel@lists.infradead.org, John Crispin , Eric Miao , Ryan Mallon , linux-kernel@vger.kernel.org, Ralf Baechle , Hartley Sweeten 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The clk_disable() in the common clock framework (drivers/clk/clk.c) returns immediately if the given clk is NULL or an error pointer. It allows drivers to call clk_disable() (and clk_disable_unprepare()) with a clock that might be NULL or an error pointer as long as the drivers are only used along with the common clock framework. Unfortunately, NULL/error checking is missing from some of non-common clk_disable() implementations. This prevents us from completely dropping NULL/error from callers. Let's add IS_ERR_OR_NULL(clk) checks to all callees. Signed-off-by: Masahiro Yamada Acked-by: Greg Ungerer Acked-by: Wan Zongshun --- arch/arm/mach-ep93xx/clock.c | 2 +- arch/arm/mach-lpc32xx/clock.c | 3 +++ arch/arm/mach-mmp/clock.c | 3 +++ arch/arm/mach-sa1100/clock.c | 15 ++++++++------- arch/arm/mach-w90x900/clock.c | 3 +++ arch/blackfin/mach-bf609/clock.c | 3 +++ arch/m68k/coldfire/clk.c | 4 ++++ arch/mips/bcm63xx/clk.c | 3 +++ arch/mips/lantiq/clk.c | 3 +++ drivers/sh/clk/core.c | 2 +- 10 files changed, 32 insertions(+), 9 deletions(-) diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c index 39ef3b6..4e11f7d 100644 --- a/arch/arm/mach-ep93xx/clock.c +++ b/arch/arm/mach-ep93xx/clock.c @@ -293,7 +293,7 @@ void clk_disable(struct clk *clk) { unsigned long flags; - if (!clk) + if (IS_ERR_OR_NULL(clk)) return; spin_lock_irqsave(&clk_lock, flags); diff --git a/arch/arm/mach-lpc32xx/clock.c b/arch/arm/mach-lpc32xx/clock.c index 661c8f4..07faac2 100644 --- a/arch/arm/mach-lpc32xx/clock.c +++ b/arch/arm/mach-lpc32xx/clock.c @@ -1125,6 +1125,9 @@ void clk_disable(struct clk *clk) { unsigned long flags; + if (IS_ERR_OR_NULL(clk)) + return; + spin_lock_irqsave(&global_clkregs_lock, flags); local_clk_disable(clk); spin_unlock_irqrestore(&global_clkregs_lock, flags); diff --git a/arch/arm/mach-mmp/clock.c b/arch/arm/mach-mmp/clock.c index 7c6f95f..7b33122 100644 --- a/arch/arm/mach-mmp/clock.c +++ b/arch/arm/mach-mmp/clock.c @@ -67,6 +67,9 @@ void clk_disable(struct clk *clk) { unsigned long flags; + if (IS_ERR_OR_NULL(clk)) + return; + WARN_ON(clk->enabled == 0); spin_lock_irqsave(&clocks_lock, flags); diff --git a/arch/arm/mach-sa1100/clock.c b/arch/arm/mach-sa1100/clock.c index cbf53bb..ea103fd 100644 --- a/arch/arm/mach-sa1100/clock.c +++ b/arch/arm/mach-sa1100/clock.c @@ -85,13 +85,14 @@ void clk_disable(struct clk *clk) { unsigned long flags; - if (clk) { - WARN_ON(clk->enabled == 0); - spin_lock_irqsave(&clocks_lock, flags); - if (--clk->enabled == 0) - clk->ops->disable(clk); - spin_unlock_irqrestore(&clocks_lock, flags); - } + if (IS_ERR_OR_NULL(clk)) + return; + + WARN_ON(clk->enabled == 0); + spin_lock_irqsave(&clocks_lock, flags); + if (--clk->enabled == 0) + clk->ops->disable(clk); + spin_unlock_irqrestore(&clocks_lock, flags); } EXPORT_SYMBOL(clk_disable); diff --git a/arch/arm/mach-w90x900/clock.c b/arch/arm/mach-w90x900/clock.c index 2c371ff..90ec250 100644 --- a/arch/arm/mach-w90x900/clock.c +++ b/arch/arm/mach-w90x900/clock.c @@ -46,6 +46,9 @@ void clk_disable(struct clk *clk) { unsigned long flags; + if (IS_ERR_OR_NULL(clk)) + return; + WARN_ON(clk->enabled == 0); spin_lock_irqsave(&clocks_lock, flags); diff --git a/arch/blackfin/mach-bf609/clock.c b/arch/blackfin/mach-bf609/clock.c index 3783058..fed8015 100644 --- a/arch/blackfin/mach-bf609/clock.c +++ b/arch/blackfin/mach-bf609/clock.c @@ -97,6 +97,9 @@ EXPORT_SYMBOL(clk_enable); void clk_disable(struct clk *clk) { + if (IS_ERR_OR_NULL(clk)) + return; + if (clk->ops && clk->ops->disable) clk->ops->disable(clk); } diff --git a/arch/m68k/coldfire/clk.c b/arch/m68k/coldfire/clk.c index fddfdcc..eb0e8c1 100644 --- a/arch/m68k/coldfire/clk.c +++ b/arch/m68k/coldfire/clk.c @@ -101,6 +101,10 @@ EXPORT_SYMBOL(clk_enable); void clk_disable(struct clk *clk) { unsigned long flags; + + if (IS_ERR_OR_NULL(clk)) + return; + spin_lock_irqsave(&clk_lock, flags); if ((--clk->enabled == 0) && clk->clk_ops) clk->clk_ops->disable(clk); diff --git a/arch/mips/bcm63xx/clk.c b/arch/mips/bcm63xx/clk.c index 6375652..d6a39bf 100644 --- a/arch/mips/bcm63xx/clk.c +++ b/arch/mips/bcm63xx/clk.c @@ -326,6 +326,9 @@ EXPORT_SYMBOL(clk_enable); void clk_disable(struct clk *clk) { + if (IS_ERR_OR_NULL(clk)) + return; + mutex_lock(&clocks_mutex); clk_disable_unlocked(clk); mutex_unlock(&clocks_mutex); diff --git a/arch/mips/lantiq/clk.c b/arch/mips/lantiq/clk.c index a0706fd..c8d87b1 100644 --- a/arch/mips/lantiq/clk.c +++ b/arch/mips/lantiq/clk.c @@ -130,6 +130,9 @@ EXPORT_SYMBOL(clk_enable); void clk_disable(struct clk *clk) { + if (IS_ERR_OR_NULL(clk)) + return; + if (unlikely(!clk_good(clk))) return; diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c index be56b22..3dd20cf 100644 --- a/drivers/sh/clk/core.c +++ b/drivers/sh/clk/core.c @@ -252,7 +252,7 @@ void clk_disable(struct clk *clk) { unsigned long flags; - if (!clk) + if (IS_ERR_OR_NULL(clk)) return; spin_lock_irqsave(&clock_lock, flags);