Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2274723imm; Mon, 24 Sep 2018 01:08:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbNHTqW4kHAJRV0juOizItLAG6dVJR1NxGLTrTUMy7IvZTTw109OZdKs3pCU186fdzuGHK3 X-Received: by 2002:a62:5d54:: with SMTP id r81-v6mr9262200pfb.88.1537776517608; Mon, 24 Sep 2018 01:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537776517; cv=none; d=google.com; s=arc-20160816; b=i5XAlQfxVxvb1w0NsAZcXSVx+IoY1tOzbZiiPKTBWX7FHooOXtSyrIguHUvX72uqNV J0ms5K15mwqCvFqwx6d+TLW9k55VrAAAoitTZoFcgamLZYyKcwLA4BhipNHnixCFi9UI MquPafGgGR8j/FcJCofMtF5C+XSimX1unJcj19cfAco8jkOqRl53imnIM9RPInqALGSC oXbPuz8rL0iC9V9lrxvl5id9IQiPXHK/o39rjxQGByquMpiAnxsGvHKeiUKATCGOCc3B g5BT3EJBmLG92kViA2A8KBRdRVj5wl8h9aMzkEepnuhqWq/L6rTGfSddBE51Q6wi1KqA PEyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JBa6cNfMJOdqf+mnmUeztcbQDvOdMgoxkEdEFDmNxF4=; b=L5gTlcr3mRpHbctONIX4b/DNdLf8DkDyy79HJS6S1FeUciuGfVIifHQEUfCxf4pec0 kS/DAFp7rqrw8CTUbv+t2Yu3Dd5Wxyk5sUtPEnpRmVNJp4PEtxcgMuM+869iKpe4V5gL 8PB4axJ75qN9wD3d91+r7Q/1mZeQ25n3+laU3/N+lPKZd9e6gYD5gr3I+QcYcTP+OEzr LMr1QAqo3kZ+0lGeIPr4pg2NOBR5NBllYdOcgr8Sd8jgYmR9F2Kv4+Ts3O24iq7PqhbL CXgrgEm4Bbw7JMcQHjY0iSOBrn2rVA5fSPcyGGb6++h+FR+lNVWi3fL/fOjwW07KidPl Ui1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=YyqV+INi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25-v6si7326389pgl.508.2018.09.24.01.08.22; Mon, 24 Sep 2018 01:08:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=YyqV+INi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbeIXOH3 (ORCPT + 99 others); Mon, 24 Sep 2018 10:07:29 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:15778 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbeIXOH3 (ORCPT ); Mon, 24 Sep 2018 10:07:29 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 24 Sep 2018 01:06:39 -0700 Received: from HQMAIL101.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 24 Sep 2018 01:06:37 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 24 Sep 2018 01:06:37 -0700 Received: from tbergstrom-lnx.Nvidia.com (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 24 Sep 2018 08:06:37 +0000 Received: by tbergstrom-lnx.Nvidia.com (Postfix, from userid 1002) id 861C8F8076D; Mon, 24 Sep 2018 11:06:31 +0300 (EEST) Date: Mon, 24 Sep 2018 11:06:31 +0300 From: Peter De Schrijver To: ryang CC: Prashant Gaikwad , Michael Turquette , Stephen Boyd , Thierry Reding , Jonathan Hunter , , , Subject: Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero Message-ID: <20180924080631.GE7636@tbergstrom-lnx.Nvidia.com> References: <20180921220037.16862-1-decatf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180921220037.16862-1-decatf@gmail.com> X-NVConfidentiality: public User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL101.nvidia.com (172.20.187.10) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1537776400; bh=JBa6cNfMJOdqf+mnmUeztcbQDvOdMgoxkEdEFDmNxF4=; h=X-PGP-Universal:Date:From:To:CC:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-NVConfidentiality:User-Agent:X-Originating-IP:X-ClientProxiedBy; b=YyqV+INiayn3aOno02S6LXOW0sWnGUsctCcFMYlklVjtBFxSMR0GCr9JuopbPzTAL FnRxi1DHkiSG8TaFE2ls15v8e96ckVMBZgL/A6o3lT5+FIpRrJYGMTaSZAwoiUI+Sk +Q4BEhhoVq81vNJ1revzE91frty/RWAuDisl/fvtTQYB31BwaT42IbyaYPW9GkhiTr KYNw6o8yx9Hqk2Fcb/x/bUtQon/fKfYKhyITvZv22DmLLDpl2gKCPwhm0iIMzPzl08 7xsfGFq2vTXJxvgEnpgqJe2JovzCcPRnzHEf+gjnN6Rtt15gn/j3OCwHDxDq2zjF9C K19Eu7NB7k6qA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 21, 2018 at 06:00:37PM -0400, ryang wrote: > Calling clk_set_rate or clk_round_rate will lock up the kernel when the > rate is zero. This avoids the infinite loop and uses a slightly more > optimized p divider calculation. > Acked-By: Peter De Schrijver At some point we should also limit pdiv to its maximum possible value, but that's not so obvious as we need to take into account PLLs where pdiv is non-linear. Peter. > Signed-off-by: ryang > --- > drivers/clk/tegra/clk-pll.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c > index 830d1c87fa7c..17a058c3bbc1 100644 > --- a/drivers/clk/tegra/clk-pll.c > +++ b/drivers/clk/tegra/clk-pll.c > @@ -582,9 +582,8 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, > } > > /* Raise VCO to guarantee 0.5% accuracy */ > - for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq; > - cfg->output_rate <<= 1) > - p_div++; > + p_div = rate ? fls((200 * cfreq) / rate) : 0; > + cfg->output_rate = rate << p_div; > > cfg->m = parent_rate / cfreq; > cfg->n = cfg->output_rate / cfreq; > -- > 2.17.1 >