From patchwork Wed Jul 4 22:09:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1157511 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 8D0293FC36 for ; Wed, 4 Jul 2012 22:14:23 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SmXmX-0001VH-LL; Wed, 04 Jul 2012 22:10:45 +0000 Received: from [194.47.250.12] (helo=mail.df.lth.se) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SmXm5-0001Un-1l for linux-arm-kernel@lists.infradead.org; Wed, 04 Jul 2012 22:10:26 +0000 Received: from mer.df.lth.se (mer.df.lth.se [194.47.250.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.df.lth.se (Postfix) with ESMTPS id ED20B65D3A; Thu, 5 Jul 2012 00:09:37 +0200 (CEST) Received: from mer.df.lth.se (triad@localhost.localdomain [127.0.0.1]) by mer.df.lth.se (8.14.3/8.14.3/Debian-9.4) with ESMTP id q64M9bKJ000677; Thu, 5 Jul 2012 00:09:37 +0200 Received: (from triad@localhost) by mer.df.lth.se (8.14.3/8.14.3/Submit) id q64M9Z1m000676; Thu, 5 Jul 2012 00:09:35 +0200 From: Linus Walleij To: Mike Turquette , Mike Turquette Subject: [PATCH] clk: allow clocks without parents to change rate Date: Thu, 5 Jul 2012 00:09:32 +0200 Message-Id: <1341439772-649-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [194.47.250.12 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Cc: Mike Turquette , Linus Walleij , linux-kernel@vger.kernel.org, stable@kernel.org, Ulf Hansson , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The clk_change_rate() code would dereference clk->parent to get clk->parent->rate without first checking that clk->parent was valid. This doesn't work if the clock is (A) a root clock and (B) can change rate. Such is the case with a VCO clock like the ICST which consequently crash like this without this patch: Unable to handle kernel NULL pointer dereference at virtual address 0000001c pgd = c0004000 [0000001c] *pgd=00000000 Internal error: Oops: 5 [#1] PREEMPT ARM Modules linked in: CPU: 0 Not tainted (3.5.0-rc3-00003-g8156866-dirty #193) PC is at clk_change_rate+0x34/0xd8 LR is at clk_change_rate+0x18/0xd8 Cc: stable@kernel.org Cc: Mike Turquette Cc: Ulf Hansson Signed-off-by: Linus Walleij --- drivers/clk/clk.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 687b00d..032d79c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -854,14 +854,22 @@ static void clk_change_rate(struct clk *clk) old_rate = clk->rate; - if (clk->ops->set_rate) - clk->ops->set_rate(clk->hw, clk->new_rate, clk->parent->rate); + if (clk->ops->set_rate) { + if (clk->parent) + clk->ops->set_rate(clk->hw, clk->new_rate, + clk->parent->rate); + else + clk->ops->set_rate(clk->hw, clk->new_rate, 0); + } - if (clk->ops->recalc_rate) - clk->rate = clk->ops->recalc_rate(clk->hw, - clk->parent->rate); - else - clk->rate = clk->parent->rate; + if (clk->ops->recalc_rate) { + if (clk->parent) + clk->rate = clk->ops->recalc_rate(clk->hw, + clk->parent->rate); + else + clk->rate = clk->ops->recalc_rate(clk->hw, 0); + } else + clk->rate = clk->parent ? clk->parent->rate : 0; if (clk->notifier_count && old_rate != clk->rate) __clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate);