From patchwork Thu Jan 21 02:42:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 8076991 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-renesas-soc@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 CCC80BEEE5 for ; Thu, 21 Jan 2016 02:43:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3C94D205E8 for ; Thu, 21 Jan 2016 02:43:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80A10205E7 for ; Thu, 21 Jan 2016 02:43:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755862AbcAUCnV (ORCPT ); Wed, 20 Jan 2016 21:43:21 -0500 Received: from kirsty.vergenet.net ([202.4.237.240]:55438 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755461AbcAUCnO (ORCPT ); Wed, 20 Jan 2016 21:43:14 -0500 Received: from reginn.isobedori.kobe.vergenet.net (p5023-ipbfp803kobeminato.hyogo.ocn.ne.jp [123.221.39.23]) by kirsty.vergenet.net (Postfix) with ESMTPA id CC5EA25B81D; Thu, 21 Jan 2016 13:43:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=verge.net.au; s=mail; t=1453344188; bh=mVYq7RIPf8mbfpy3IW0ww9juuLtFMqnTbBDijqLBbHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=dwC50BVRE2tlibciUvdF/px/fBiyNOowQisqBcSsugPCmFG/m9nc6QBhpkbkr9j4r zixvy9ocOt5qbybhyAT+sdIiVNJrRsTxqaSoTRV/0pN8+i/CpQ0voa0e5rJPmwpI7e 08GQ7hKfUD6UL+l9djFd/wlb8y+3usawnurKcHck= Received: by reginn.isobedori.kobe.vergenet.net (Postfix, from userid 7100) id 112919404FB; Thu, 21 Jan 2016 11:43:08 +0900 (JST) From: Simon Horman To: Linus Torvalds Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Magnus Damm , Guenter Roeck , Geert Uytterhoeven , Simon Horman Subject: [PATCH 2/2] drivers: sh: clk: Avoid crashes when passing NULL clocks Date: Thu, 21 Jan 2016 11:42:52 +0900 Message-Id: <6575a9c69a211ac1cf454f9c76be54f7a5fae9fe.1453343708.git.horms+renesas@verge.net.au> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 From: Geert Uytterhoeven Several clock API functions handle NULL clocks when the Common Clock Framework is used, while their legacy SH counterparts don't, and would just crash when a NULL clock is passed. Add NULL checks to clk_get_rate(), clk_set_rate(), clk_get_parent(), and clk_round_rate(), to avoid different behavior in drivers shared between legacy and CCF-based platforms. Signed-off-by: Geert Uytterhoeven Signed-off-by: Simon Horman --- drivers/sh/clk/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c index 6bf973bd9654..92863e3818e5 100644 --- a/drivers/sh/clk/core.c +++ b/drivers/sh/clk/core.c @@ -469,6 +469,9 @@ void clk_enable_init_clocks(void) unsigned long clk_get_rate(struct clk *clk) { + if (!clk) + return 0; + return clk->rate; } EXPORT_SYMBOL_GPL(clk_get_rate); @@ -478,6 +481,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate) int ret = -EOPNOTSUPP; unsigned long flags; + if (!clk) + return 0; + spin_lock_irqsave(&clock_lock, flags); if (likely(clk->ops && clk->ops->set_rate)) { @@ -535,12 +541,18 @@ EXPORT_SYMBOL_GPL(clk_set_parent); struct clk *clk_get_parent(struct clk *clk) { + if (!clk) + return NULL; + return clk->parent; } EXPORT_SYMBOL_GPL(clk_get_parent); long clk_round_rate(struct clk *clk, unsigned long rate) { + if (!clk) + return 0; + if (likely(clk->ops && clk->ops->round_rate)) { unsigned long flags, rounded;