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: 86316 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp311150qgi; Fri, 2 Dec 2016 07:39:52 -0800 (PST) X-Received: by 10.99.204.81 with SMTP id q17mr80222199pgi.168.1480693192220; Fri, 02 Dec 2016 07:39:52 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f192si5696141pfa.60.2016.12.02.07.39.51; Fri, 02 Dec 2016 07:39:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752993AbcLBPjf (ORCPT + 13 others); Fri, 2 Dec 2016 10:39:35 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38598 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbcLBPjc (ORCPT ); Fri, 2 Dec 2016 10:39:32 -0500 Received: by mail-wm0-f41.google.com with SMTP id f82so19174385wmf.1 for ; Fri, 02 Dec 2016 07:39:31 -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=JaDlry7bcA8q0PY/smpD98Ye3JEY9pmzTxSlHeo8nmjOYOvdSA0KC/TKYgSci9OyQa 9hLrPQ1YNG0UzPUs2QzEDszBUVVIX1bK1jHs6xwFC4WPnuzFJFlZtR0xfudZISom1IAo 0h5bkZz+oQcr/eQDljSrZ54jjDQGPro60Ku8pChmDYek8UmV3uk7z7zQvIPrjtlVnGHA cRopKAwb4Ryx8LnfbtcdkBuUhf1O2nV5qB4bZWhvWagNUPaXx36eZDfdCB+zbstipifG OuGAbkF3l59CUEkpHNZzA6R2cS69HhRLhkdHc7WC499cjFgJHdxzs/F0z/syfcWTx+Jb r3yw== X-Gm-Message-State: AKaTC03VMiiJQeZFKiTROfsvOdb4QFD43BQQfb1G8JHKC77DwpV2XxcCYo/ph4toi6w/yDYM 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 Cc: LKML , arm-soc , linux-pm@vger.kernel.org, Bartosz Golaszewski 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> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- arch/arm/mach-davinci/da850.c | 22 ++++++++++++++++++---- drivers/cpufreq/davinci-cpufreq.c | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Viresh Kumar 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;