From patchwork Sun Apr 19 12:13:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 29208 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1Yjo75-0004PC-Rd; Sun, 19 Apr 2015 14:14:15 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.76/mailfrontend-6) with esmtp id 1Yjo73-0002v4-3S; Sun, 19 Apr 2015 14:14:15 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751922AbbDSMNr (ORCPT + 1 other); Sun, 19 Apr 2015 08:13:47 -0400 Received: from gloria.sntech.de ([95.129.55.99]:38250 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751610AbbDSMNp (ORCPT ); Sun, 19 Apr 2015 08:13:45 -0400 Received: from ip92344031.dynamic.kabel-deutschland.de ([146.52.64.49] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Yjo5x-0004OA-H0; Sun, 19 Apr 2015 14:13:05 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Boris Brezillon Cc: Mike Turquette , Mikko Perttunen , Jonathan Corbet , Shawn Guo , ascha Hauer , David Brown , Daniel Walker , Bryan Huntsman , Tony Lindgren , Paul Walmsley , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi , Ralf Baechle , Max Filippov , Sylwester Nawrocki , Tomasz Figa , Barry Song , Viresh Kumar , Emilio =?ISO-8859-1?Q?L=F3pez?= , Maxime Ripard , Peter De Schrijver , Prashant Gaikwad , Stephen Warren , Thierry Reding , Alexandre Courbot , Tero Kristo , Ulf Hansson , Michal Simek , Philipp Zabel , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-omap@vger.kernel.org, linux-mips@linux-mips.org, patches@opensource.wolfsonmicro.com, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, spear-devel@list.st.com, linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, rtc-linux@googlegroups.com Subject: Re: [PATCH 1/2] clk: change clk_ops' ->round_rate() prototype Date: Sun, 19 Apr 2015 14:13:04 +0200 Message-ID: <7408975.lBcgZIN9hf@diego> User-Agent: KMail/4.14.1 (Linux/3.16.0-4-amd64; KDE/4.14.2; x86_64; ; ) In-Reply-To: <1429255769-13639-2-git-send-email-boris.brezillon@free-electrons.com> References: <1429255769-13639-1-git-send-email-boris.brezillon@free-electrons.com> <1429255769-13639-2-git-send-email-boris.brezillon@free-electrons.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2015.4.19.120318 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, INVALID_MSGID_NO_FQDN 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FORWARDED_MSG 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' Hi Boris, Am Freitag, 17. April 2015, 09:29:28 schrieb Boris Brezillon: > Clock rates are stored in an unsigned long field, but ->round_rate() > (which returns a rounded rate from a requested one) returns a long > value (errors are reported using negative error codes), which can lead > to long overflow if the clock rate exceed 2Ghz. > > Change ->round_rate() prototype to return 0 or an error code, and pass the > requested rate as a pointer so that it can be adjusted depending on > hardware capabilities. > > Signed-off-by: Boris Brezillon > --- On a rk3288-veyron-pinky with the fix described below: Tested-by: Heiko Stuebner > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index fa5a00e..1462ddc 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -1640,8 +1643,10 @@ static struct clk_core *clk_calc_new_rates(struct > clk_core *clk, &parent_hw); > parent = parent_hw ? parent_hw->core : NULL; > } else if (clk->ops->round_rate) { > - new_rate = clk->ops->round_rate(clk->hw, rate, > - &best_parent_rate); > + if (clk->ops->round_rate(clk->hw, &new_rate, > + &best_parent_rate)) > + return NULL; > + > if (new_rate < min_rate || new_rate > max_rate) > return NULL; > } else if (!parent || !(clk->flags & CLK_SET_RATE_PARENT)) { This is using new_rate uninitialized when calling into the round_rate callback. Which in turn pushed my PLLs up to 2.2GHz :-) I guess you'll need something like the following: > diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c > index f8d3baf..bd408ef 100644 > --- a/drivers/clk/rockchip/clk-pll.c > +++ b/drivers/clk/rockchip/clk-pll.c > @@ -63,8 +63,8 @@ static const struct rockchip_pll_rate_table > *rockchip_get_pll_settings( return NULL; > } > > -static long rockchip_pll_round_rate(struct clk_hw *hw, > - unsigned long drate, unsigned long *prate) > +static int rockchip_pll_round_rate(struct clk_hw *hw, > + unsigned long *drate, unsigned long *prate) > { > struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw); > const struct rockchip_pll_rate_table *rate_table = pll->rate_table; > @@ -72,12 +72,15 @@ static long rockchip_pll_round_rate(struct clk_hw *hw, > > /* Assumming rate_table is in descending order */ > for (i = 0; i < pll->rate_count; i++) { > - if (drate >= rate_table[i].rate) > - return rate_table[i].rate; > + if (*drate >= rate_table[i].rate) { > + *drate = rate_table[i].rate; > + return 0; > + } > } > > /* return minimum supported value */ > - return rate_table[i - 1].rate; > + *drate = rate_table[i - 1].rate; > + return 0; > } > > /* The rockchip-part: Reviewed-by: Heiko Stuebner And as I've stumbled onto this recently too, the clock-maintainership has expanded to Stephen Boyd and linux-clk@vger.kernel.org . Heiko --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index db4e4b2..afc7733 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1605,6 +1605,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *clk, &parent_hw); parent = parent_hw ? parent_hw->core : NULL; } else if (clk->ops->round_rate) { + new_rate = rate; if (clk->ops->round_rate(clk->hw, &new_rate, &best_parent_rate)) return NULL;