From patchwork Mon Dec 3 08:14:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 1832271 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 3A4D43FC5A for ; Mon, 3 Dec 2012 08:18:15 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TfRAy-00040D-Sw; Mon, 03 Dec 2012 08:14:52 +0000 Received: from mail-da0-f49.google.com ([209.85.210.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TfRAv-0003zu-Cr for linux-arm-kernel@lists.infradead.org; Mon, 03 Dec 2012 08:14:50 +0000 Received: by mail-da0-f49.google.com with SMTP id v40so1022479dad.36 for ; Mon, 03 Dec 2012 00:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=fDRjDLSNEgDnl5z82Wjv9tuza1flYrtEMm7xzHacJ4k=; b=x3HxVvZuKOM69aehibbLWEz/c8D22Kg4QptDTS9pXgEovpU4DXjsfmK7ixavkmLvx0 0Nq4msjIiXqbkYif+6yIGpFRTztRjTVn+vn+Zz7y8sn+OLeubcTWelPgl5dVVY3AFmfv 69e+SGmum64b7BYAA20AvJyUivBqj5JsRVuBYU9JbCFwb8hoEWKaKhU4MGJxF/G/2Qzk oj9htaWYoYpXGUR6sU0/vG5WBvzbaGVGfX56mddCIHJO73wXjv5pqIAV3FHg/vXRvPBh 6k7wie0aDzmc8Rib3rpO35NXOeNdq+MCJWNpNZGGoKj1KQUF3dnr7bwgGxXIg5gLM+Ab 1fuA== Received: by 10.68.213.233 with SMTP id nv9mr26868871pbc.155.1354522486792; Mon, 03 Dec 2012 00:14:46 -0800 (PST) Received: from localhost.localdomain ([174.139.116.75]) by mx.google.com with ESMTPS id ot5sm7675063pbb.29.2012.12.03.00.14.43 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 03 Dec 2012 00:14:45 -0800 (PST) From: Haojian Zhuang To: mturquette@ti.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: factor: calculate rate by do_div Date: Mon, 3 Dec 2012 16:14:37 +0800 Message-Id: <1354522477-11991-1-git-send-email-haojian.zhuang@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121203_031449_691801_A1A8241F X-CRM114-Status: GOOD ( 10.54 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (haojian.zhuang[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Haojian Zhuang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org clk->rate = parent->rate / div * mult The formula is OK. But it may overflow while we do operate with unsigned long. So use do_div instead. Signed-off-by: Haojian Zhuang --- drivers/clk/clk-fixed-factor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index a489985..1ef271e 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -28,8 +28,11 @@ static unsigned long clk_factor_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_fixed_factor *fix = to_clk_fixed_factor(hw); + unsigned long long int rate; - return parent_rate * fix->mult / fix->div; + rate = (unsigned long long int)parent_rate * fix->mult; + do_div(rate, fix->div); + return (unsigned long)rate; } static long clk_factor_round_rate(struct clk_hw *hw, unsigned long rate,