Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp592084img; Fri, 22 Mar 2019 04:44:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSuC4n7VgMVVrXPUfQGSHWY2R8TVBcXTFO0GNAqdZYzaD9O6niHpgiWTVzbjUmpJqL2qbS X-Received: by 2002:a17:902:8d8b:: with SMTP id v11mr9172570plo.241.1553255055359; Fri, 22 Mar 2019 04:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255055; cv=none; d=google.com; s=arc-20160816; b=uhb8grE5MVYSgnTFU/MLpURw10NkqMMlDhtA4MfM7Vjy1M5oOrILqH1g9u3YKIi+Xm mwD8b5Qk6mMLAmI5pM/PtyUyQpi1LRUvXQOcDb39wKJ4NgMt70tBPDljSkhtpSLYFLQ0 tJXEg0zB7AZCGHkG2oYS9eASzA9kVStJGQeir2jkMrMXZ9TrE6160IMy6xvYD5WBKMad YzvRsJQ7kc1gUIKHWX7UtDP4+Nt6b7XWWfgwTwHsfzNhwRkEh75ClUCfqXf3/dLBhuHB Qu3ZwqkrUlqpVk1+vWgUouatMt26Atsj7jzs7a7SpfpXEx7BQix3KKRjmZG5NANmFwgS rQ0w== 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=fYusPqVnGbj8d3MCB5mbXAHVqy/38TI5muSl/97GENY=; b=wAugb3N1eMXsS8iG/xnUMzwe5iXLQt8i2iyqmd6IOE6XikF8jf1F7O43iHNPreHLYW Y0J/D/zSTuBU07rTOJ2TLk1PwyF3BmFUbUeOry6SDfMN2u+WGZPWKWAweVb6cNWmLaTD 81rHnc8wVzIZgzntIES+YIcrsYbVWHc8mHyqH2YPDzVaZUs/bCigrV/bf9vPYjH/ahKW skVRM0dJUJlVfTsk1DjKxoKwOOSngeelzsCmlxEvUpof/r+tP1raPucV5I1Pv9+FpBjI 3OVMO7xFepi0a0GH/R43kf31GLcqnaGCcXMNzHY71FJNR/TDeI2ZZtH1aXUBRns74gCO 3G8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KcKbbR8i; 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 z3si6372742pgv.295.2019.03.22.04.43.57; Fri, 22 Mar 2019 04:44:15 -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=KcKbbR8i; 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 S1731654AbfCVLnT (ORCPT + 99 others); Fri, 22 Mar 2019 07:43:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727954AbfCVLnS (ORCPT ); Fri, 22 Mar 2019 07:43:18 -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 7ECFB204FD; Fri, 22 Mar 2019 11:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254998; bh=aLUFDYJc4/n/Llle+hrNDdaY9Cq75axnQ1+kFQv30+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KcKbbR8iAQe9IJ/Un9Fb7pc57svd0tPOLiNXStzQAGDqn5bWwttecWZLTIltxtnOp rgk0sELFYK3K6KKlLXajHThiRY3TFMM13MUMBqacG9ZsNlf/GnYZdaZNXVmzcbCNlD bRx9ih3byF8kbkPK13TqVW20I9CSqpwqNnii3yoE= 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.9 075/118] clk: ingenic: Fix round_rate misbehaving with non-integer dividers Date: Fri, 22 Mar 2019 12:15:47 +0100 Message-Id: <20190322111221.916626082@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111215.873964544@linuxfoundation.org> References: <20190322111215.873964544@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.9-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 @@ -364,16 +364,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 @@ -393,7 +393,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;