From patchwork Fri Dec 2 15:38:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 9458825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B93F460515 for ; Fri, 2 Dec 2016 15:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACDFA2849B for ; Fri, 2 Dec 2016 15:42:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A115B284F0; Fri, 2 Dec 2016 15:42:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 394492849B for ; Fri, 2 Dec 2016 15:42:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCpwv-0003iR-68; Fri, 02 Dec 2016 15:40:33 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCpwH-0001vo-73 for linux-arm-kernel@lists.infradead.org; Fri, 02 Dec 2016 15:39:54 +0000 Received: by mail-wm0-x229.google.com with SMTP id t79so19182085wmt.0 for ; Fri, 02 Dec 2016 07:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u950LwipckvS5o90OVPnd5U+x59PSqJgp7qeHQRFH8k=; b=Td7pAwnt0lQ+uIsdIlKmaJ8OtT3w+ffsDtCYyzf0q36P/3f9EPIcAS+iqW8i9l66xu 5dw79tw0LT7Olq1UrLavcPQpUvNI2kIQqHhQ4hqPxgx+Xkr9mEu3/17/8gfgRj3xIdFl HtiK0MjVh4xgfMYDycHtq+yeKSmGMPt8Vr5vJrzVD4DV9p359rx1DYdJyCDBJwSIXJhN 5+TafLj7nri9F//WmjonI+tmrG3RlWEKie17c/LxTIxWrEv5hd/ChIS1hneU8yD8V1uk ctKTMA7erc6zoxiih9jjSxrhGjefYwNE+HDjZo0hgjyEoaGwTXymr2Cmv6qRCo4AUjib nj7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u950LwipckvS5o90OVPnd5U+x59PSqJgp7qeHQRFH8k=; b=akiclwikNNQn/QgUF9xhCdbeqdxnb3hc7fJ/4UJ0mHE4STgKtucVgGJUgjewrY5f25 8d7f9Ftt4CeTToUAjM/K71XcpblBLDhW5mF8k5BruP6/HCBYlyGmQ6DprqZfJ/lTkqwd HYhNScSnPop/B5Y1kwrsNaLR8ZykVqzwy0OwO1XyM3G/NyLI801RUYd1fK3F1iY0nN1l 4moGqx+0Z1okhv7Np61OlrMytzE9ZttcmtyoZFwQ4g/2hBFc9mMzWK/br8hporozjlIY TfIxWaalEcMOOSJJvPfvWs0VQnZYnsxLkee3U1WyVVNmRUc+BzcHCvlUvG/OjXStBAXy sYyg== X-Gm-Message-State: AKaTC00iI3zqeWMnd+4at+FToTC/s/oA5kkdGh4hVisVPZ/GgpM19wef6kprIn6e15yQte/K X-Received: by 10.28.166.208 with SMTP id p199mr3442334wme.27.1480693171122; Fri, 02 Dec 2016 07:39:31 -0800 (PST) Received: from bgdev-debian.lan (jua06-1-82-242-157-225.fbx.proxad.net. [82.242.157.225]) by smtp.gmail.com with ESMTPSA id x140sm3769666wme.19.2016.12.02.07.39.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Dec 2016 07:39:30 -0800 (PST) From: Bartosz Golaszewski To: Kevin Hilman , Michael Turquette , Sekhar Nori , Peter Ujfalusi , Russell King , Viresh Kumar , Boris Brezillon , "Rafael J. Wysocki" , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen Subject: [PATCH v2 3/3] ARM: da850: fix da850_set_pll0rate() Date: Fri, 2 Dec 2016 16:38:54 +0100 Message-Id: <1480693134-31324-4-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1480693134-31324-1-git-send-email-bgolaszewski@baylibre.com> References: <1480693134-31324-1-git-send-email-bgolaszewski@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161202_073953_487021_13FBEBDA X-CRM114-Status: GOOD ( 15.39 ) 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: Bartosz Golaszewski , LKML , arm-soc , linux-pm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This function is broken - its second argument is an index to the freq table, not the requested clock rate in Hz. It leads to an oops when called from clk_set_rate() since this argument isn't bounds checked either. Fix it by iterating over the array of supported frequencies and selecting a one that matches or returning -EINVAL for unsupported rates. Also: update the davinci cpufreq driver. It's the only user of this clock and currently it passes the cpufreq table index to clk_set_rate(), which is confusing. Make it pass the requested clock rate in Hz. Signed-off-by: Bartosz Golaszewski Acked-by: Viresh Kumar --- arch/arm/mach-davinci/da850.c | 22 ++++++++++++++++++---- drivers/cpufreq/davinci-cpufreq.c | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c index a55101c..92e3303 100644 --- a/arch/arm/mach-davinci/da850.c +++ b/arch/arm/mach-davinci/da850.c @@ -1179,14 +1179,28 @@ static int da850_set_armrate(struct clk *clk, unsigned long index) return clk_set_rate(pllclk, index); } -static int da850_set_pll0rate(struct clk *clk, unsigned long index) +static int da850_set_pll0rate(struct clk *clk, unsigned long rate) { - unsigned int prediv, mult, postdiv; - struct da850_opp *opp; struct pll_data *pll = clk->pll_data; + struct cpufreq_frequency_table *freq; + unsigned int prediv, mult, postdiv; + struct da850_opp *opp = NULL; int ret; - opp = (struct da850_opp *) cpufreq_info.freq_table[index].driver_data; + for (freq = da850_freq_table; + freq->frequency != CPUFREQ_TABLE_END; freq++) { + /* requested_rate is in Hz, freq->frequency is in KHz */ + unsigned long freq_rate = freq->frequency * 1000; + + if (freq_rate == rate) { + opp = (struct da850_opp *)freq->driver_data; + break; + } + } + + if (opp == NULL) + return -EINVAL; + prediv = opp->prediv; mult = opp->mult; postdiv = opp->postdiv; diff --git a/drivers/cpufreq/davinci-cpufreq.c b/drivers/cpufreq/davinci-cpufreq.c index b95a872..d54a27c 100644 --- a/drivers/cpufreq/davinci-cpufreq.c +++ b/drivers/cpufreq/davinci-cpufreq.c @@ -55,7 +55,7 @@ static int davinci_target(struct cpufreq_policy *policy, unsigned int idx) return ret; } - ret = clk_set_rate(armclk, idx); + ret = clk_set_rate(armclk, new_freq * 1000); if (ret) return ret;