Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp611975img; Fri, 22 Mar 2019 05:08:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyC4DkAbiSSjeKij2CBshdISvNd3YdRItjkCIA7wEcqBJrTIxlZHw4GENbhMB9t6pF6ioYs X-Received: by 2002:a17:902:407:: with SMTP id 7mr9266589ple.62.1553256530838; Fri, 22 Mar 2019 05:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256530; cv=none; d=google.com; s=arc-20160816; b=bZm7vguax4pbNEjR6VIIHtxBJ6qQc2fdmznwLmn7SQXOlMo8SLTydw+ejG4oYlCj0K ykPFpZhySV7fJQ7myLywsRNzcoRxcWoNP29PJvcGnwiXbU/c7Cp11G4FwgXrS4nAJecS EeX+NZbbX4HVeIzaldny/N35uSGTGffND/+KBM1dtZge7uGVbdnroHrfHAN8oNa3zwg7 IF5ctKycUGHDlARv2OP7ZjNEOQgzpQWa6B0TNsbThopPy/PQg4oN8ucXc50lXHXf42iC 59Vq73T1K6i0qxvipkgPvvbr244KNHqQJ4vZyW+Hd8Tfp70leC41oFU4LGkaXGUJt3LS qyRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AAhZOWQgN5VAkVK32p39IHvst7qOD+KwyMwTABHh+P4=; b=zDXAb6rZmROEx6oBXkKS4XdLUT6otTS1vJeeVpLJN1MK/Rkwk17KTpCCHeHxwONH1W yuJqfxuC87uipKSvAMnbymblsSIoXKSWHvlqqFbI/1QbixK0PamnBTm084fhp8YFstRY vR2TRAmF2kbR0/WfGy/ZemiBTVQg8TAj+KCAqPvq4T1Q2VikgDIycKwWZuWES0Bvkx0o BX7AGlRPTQFNkJyz5n7XlRAnyENCNifASlyWV1eY+JYzN+6nZxjy3eusTWi4PKWTp7G8 /Q3i2UeY4A9W5qCSc9EixXL5fHwLYlPiPe1FzZEGLGWroL35biCyFviGVQspYQvdztxP xGHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YjF8yTf5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10si6285804pgr.112.2019.03.22.05.08.33; Fri, 22 Mar 2019 05:08:50 -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=@kernel.org header.s=default header.b=YjF8yTf5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388833AbfCVMHh (ORCPT + 99 others); Fri, 22 Mar 2019 08:07:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:45964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389049AbfCVMHe (ORCPT ); Fri, 22 Mar 2019 08:07:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A7A9206C0; Fri, 22 Mar 2019 12:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256453; bh=XohDEVTxcIbZ3XpInH44l9uYi7IDA7YUjiuouiGTdT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YjF8yTf5jmeeQOmot0cf5T37XLcOmzU5BAoIjIXv03Lht00hRLaiu8Yd+utNfR8fh 4qMqbtv19eIkq2Ns9L7o5BK/ak133yhAL6NhYEtXzaOvEmgxoaR8+9SkGL8oTpWpIb +rHnOtcF2t+7udGx4E2mE4qhOjKO7qdVFYk80QwI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Cercueil , Maarten ter Huurne , Stephen Boyd Subject: [PATCH 4.19 195/280] clk: ingenic: Fix round_rate misbehaving with non-integer dividers Date: Fri, 22 Mar 2019 12:15:48 +0100 Message-Id: <20190322111329.530403606@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Cercueil commit bc5d922c93491878c44c9216e9d227c7eeb81d7f upstream. Take a parent rate of 180 MHz, and a requested rate of 4.285715 MHz. This results in a theorical divider of 41.999993 which is then rounded up to 42. The .round_rate function would then return (180 MHz / 42) as the clock, rounded down, so 4.285714 MHz. Calling clk_set_rate on 4.285714 MHz would round the rate again, and give a theorical divider of 42,0000028, now rounded up to 43, and the rate returned would be (180 MHz / 43) which is 4.186046 MHz, aka. not what we requested. Fix this by rounding up the divisions. Signed-off-by: Paul Cercueil Tested-by: Maarten ter Huurne Cc: Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/ingenic/cgu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/clk/ingenic/cgu.c +++ b/drivers/clk/ingenic/cgu.c @@ -426,16 +426,16 @@ ingenic_clk_round_rate(struct clk_hw *hw struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw); struct ingenic_cgu *cgu = ingenic_clk->cgu; const struct ingenic_cgu_clk_info *clk_info; - long rate = *parent_rate; + unsigned int div = 1; clk_info = &cgu->clock_info[ingenic_clk->idx]; if (clk_info->type & CGU_CLK_DIV) - rate /= ingenic_clk_calc_div(clk_info, *parent_rate, req_rate); + div = ingenic_clk_calc_div(clk_info, *parent_rate, req_rate); else if (clk_info->type & CGU_CLK_FIXDIV) - rate /= clk_info->fixdiv.div; + div = clk_info->fixdiv.div; - return rate; + return DIV_ROUND_UP(*parent_rate, div); } static int @@ -455,7 +455,7 @@ ingenic_clk_set_rate(struct clk_hw *hw, if (clk_info->type & CGU_CLK_DIV) { div = ingenic_clk_calc_div(clk_info, parent_rate, req_rate); - rate = parent_rate / div; + rate = DIV_ROUND_UP(parent_rate, div); if (rate != req_rate) return -EINVAL;