From patchwork Thu Apr 12 01:02:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 7751 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 14C3923E29 for ; Thu, 12 Apr 2012 01:07:49 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id CFCC1A18142 for ; Thu, 12 Apr 2012 01:07:48 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so2812921iag.11 for ; Wed, 11 Apr 2012 18:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:x-gm-message-state; bh=0J8Gez9YaC0iaY9JwM0qUxGaLQJ6A+l9wQglYIL5MwE=; b=NLhAGqHR1BJuVpO75eb250ZDCnf/g/I1umpkqxzezL7cpojIN9guYSLmDoY4+VY7nW V8fSyacYXcCSHz+bqgxVT/qPRhQw3cgRi4MRulcCukdKoUykl4ZXd+ctiFIL58AYV2Q+ Nx5WPixMyQsmDk7+uIun2fodgVZua7Zk7PvExve4NNdVgRHK/M+F/HiJ0mn7OrH3lLmK rIl9LfVnH9hFsc4VZkJ5If7JqvGkp2tIbwIPjYRUt2Z3way0HdDuaNRR3aUWnj6wH+iC uqCSro2WfXpNFe6DeVPUrISgjsF04UhUNgb1fEhDhQWSLxnkKBLayOc5v5ifSASIf4rm LisQ== Received: by 10.50.51.197 with SMTP id m5mr319247igo.38.1334192868617; Wed, 11 Apr 2012 18:07:48 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.164.217 with SMTP id f25csp161859iby; Wed, 11 Apr 2012 18:07:48 -0700 (PDT) Received: by 10.60.0.135 with SMTP id 7mr665384oee.25.1334192867553; Wed, 11 Apr 2012 18:07:47 -0700 (PDT) Received: from comal.ext.ti.com (comal.ext.ti.com. [198.47.26.152]) by mx.google.com with ESMTPS id uh8si403198obb.70.2012.04.11.18.07.47 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 Apr 2012 18:07:47 -0700 (PDT) Received-SPF: neutral (google.com: 198.47.26.152 is neither permitted nor denied by best guess record for domain of mturquette@linaro.org) client-ip=198.47.26.152; Authentication-Results: mx.google.com; spf=neutral (google.com: 198.47.26.152 is neither permitted nor denied by best guess record for domain of mturquette@linaro.org) smtp.mail=mturquette@linaro.org Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id q3C17YFH023735; Wed, 11 Apr 2012 20:07:34 -0500 Received: from DFLE71.ent.ti.com (dfle71.ent.ti.com [128.247.5.62]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q3C17Ytk002611; Wed, 11 Apr 2012 20:07:34 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by dfle71.ent.ti.com (128.247.5.62) with Microsoft SMTP Server id 14.1.323.3; Wed, 11 Apr 2012 20:07:34 -0500 Received: from nucleus.nsc.com (nucleus.nsc.com [10.188.36.112]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id q3C17Pn4005839; Wed, 11 Apr 2012 20:07:33 -0500 From: Mike Turquette To: CC: , , , , Mike Turquette , Olof Johansson , Russell King , Sascha Hauer , Shawn Guo , Richard Zhao , Saravana Kannan , Mark Brown , Andrew Lunn , Viresh Kumar Subject: [PATCH 03/13] clk: core: clk_calc_new_rates handles NULL parents Date: Wed, 11 Apr 2012 18:02:41 -0700 Message-ID: <1334192572-12499-4-git-send-email-mturquette@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1334192572-12499-1-git-send-email-mturquette@linaro.org> References: <1334192572-12499-1-git-send-email-mturquette@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlNKxb5zsFS/4TfaIwYKpNvSi6YW8LQxg4bgyCJ5JaU79dVrWnkR5oOpo4Ompj/4SiMR55u It is possible to call clk_set_rate on a clock with a NULL parent. One such example is an adjustable-rate root clock. Ensure that clk_calc_new_rates does not dereference parent without checking first and also handle the corner cases gracefully. Reported-by: Rajendra Nayak Signed-off-by: Mike Turquette Cc: Arnd Bergman Cc: Olof Johansson Cc: Russell King Cc: Sascha Hauer Cc: Shawn Guo Cc: Richard Zhao Cc: Saravana Kannan Cc: Mark Brown Cc: Andrew Lunn Cc: Viresh Kumar --- drivers/clk/clk.c | 29 +++++++++++++++++++++-------- 1 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 4daacf5..d83a9e0 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -763,25 +763,38 @@ static void clk_calc_subtree(struct clk *clk, unsigned long new_rate) static struct clk *clk_calc_new_rates(struct clk *clk, unsigned long rate) { struct clk *top = clk; - unsigned long best_parent_rate = clk->parent->rate; + unsigned long best_parent_rate; unsigned long new_rate; - if (!clk->ops->round_rate && !(clk->flags & CLK_SET_RATE_PARENT)) { - clk->new_rate = clk->rate; + /* sanity */ + if (IS_ERR_OR_NULL(clk)) + return NULL; + + /* never propagate up to the parent */ + if (!(clk->flags & CLK_SET_RATE_PARENT)) { + if (!clk->ops->round_rate) { + clk->new_rate = clk->rate; + return NULL; + } else { + new_rate = clk->ops->round_rate(clk->hw, rate, NULL); + goto out; + } + } + + /* need clk->parent from here on out */ + if (!clk->parent) { + pr_debug("%s: %s has NULL parent\n", __func__, clk->name); return NULL; } - if (!clk->ops->round_rate && (clk->flags & CLK_SET_RATE_PARENT)) { + if (!clk->ops->round_rate) { top = clk_calc_new_rates(clk->parent, rate); new_rate = clk->new_rate = clk->parent->new_rate; goto out; } - if (clk->flags & CLK_SET_RATE_PARENT) - new_rate = clk->ops->round_rate(clk->hw, rate, &best_parent_rate); - else - new_rate = clk->ops->round_rate(clk->hw, rate, NULL); + new_rate = clk->ops->round_rate(clk->hw, rate, &best_parent_rate); if (best_parent_rate != clk->parent->rate) { top = clk_calc_new_rates(clk->parent, best_parent_rate);