From patchwork Wed Feb 19 21:11:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinh Nguyen X-Patchwork-Id: 3683121 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A2687BF13A for ; Wed, 19 Feb 2014 21:15:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D8FC8201BA for ; Wed, 19 Feb 2014 21:15:41 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB97F20155 for ; Wed, 19 Feb 2014 21:15:40 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGETd-00027H-Pa; Wed, 19 Feb 2014 21:14:46 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGETP-0000FE-5b; Wed, 19 Feb 2014 21:14:31 +0000 Received: from mail-bl2on0772.outbound.protection.outlook.com ([2a01:111:f400:fc09::772] helo=na01-bl2-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGETJ-0000DT-H4 for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2014 21:14:29 +0000 Received: from BL2FFO11FD027.protection.gbl (10.173.160.34) by BL2FFO11HUB016.protection.gbl (10.173.160.108) with Microsoft SMTP Server (TLS) id 15.0.868.13; Wed, 19 Feb 2014 21:13:32 +0000 Received: from SJ-ITEXEDGE02.altera.priv.altera.com (66.35.236.232) by BL2FFO11FD027.mail.protection.outlook.com (10.173.161.106) with Microsoft SMTP Server (TLS) id 15.0.868.13 via Frontend Transport; Wed, 19 Feb 2014 21:13:32 +0000 Received: from sj-mail01.altera.com (137.57.1.6) by SJ-ITEXEDGE02.altera.priv.altera.com (66.35.236.232) with Microsoft SMTP Server id 8.3.342.0; Wed, 19 Feb 2014 13:00:52 -0800 Received: from linux-builds1.altera.com (linux-builds1.altera.com [137.57.188.114]) by sj-mail01.altera.com (8.13.7+Sun/8.13.7) with ESMTP id s1JLDRWE004935; Wed, 19 Feb 2014 13:13:30 -0800 (PST) From: To: Subject: [PATCH 1/3] clk: socfpga: Fix integer overflow in clock calculation Date: Wed, 19 Feb 2014 15:11:10 -0600 Message-ID: <1392844273-11918-1-git-send-email-dinguyen@altera.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:66.35.236.232; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019001)(6009001)(189002)(199002)(87266001)(95666001)(65816001)(87286001)(80022001)(74366001)(69226001)(92726001)(85306002)(93136001)(81542001)(47736001)(74662001)(33646001)(85852003)(80976001)(83072002)(53806001)(81342001)(89996001)(48376002)(86152002)(90146001)(94946001)(56816005)(74502001)(50986001)(4396001)(62966002)(87936001)(46102001)(54316002)(94316002)(49866001)(47976001)(50226001)(95416001)(31966008)(47446002)(20776003)(83322001)(88136002)(74876001)(74706001)(77982001)(81686001)(56776001)(59766001)(76176001)(50466002)(81816001)(93516002)(86362001)(92566001)(36756003)(47776003)(79102001)(93916002)(77096001)(76786001)(6806004)(19580405001)(19580395003)(76482001)(51856001)(77156001)(44976005)(76796001)(63696002)(53416003); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2FFO11HUB016; H:SJ-ITEXEDGE02.altera.priv.altera.com; CLIP:66.35.236.232; FPR:23BEFB66.30EAA7C8.32F51B33.90BA1A49.20199; MLV:nspm; InfoDomainNonexistentMX:1; A:1; LANG:en; X-OriginatorOrg: altera.onmicrosoft.com X-Forefront-PRVS: 012792EC17 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140219_161427_893841_C85F2A61 X-CRM114-Status: UNSURE ( 7.76 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) Cc: Graham Moore , Steffen Trumtrar , dinh.linux@gmail.com, Dinh Nguyen , Mike Turquette X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dinh Nguyen Use 64-bit integer for calculating clock rate. Also use do_div for the 64-bit division. Signed-off-by: Graham Moore Signed-off-by: Dinh Nguyen Cc: Mike Turquette Cc: Steffen Trumtrar --- drivers/clk/socfpga/clk-pll.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c index 362004e..834b6e9 100644 --- a/drivers/clk/socfpga/clk-pll.c +++ b/drivers/clk/socfpga/clk-pll.c @@ -44,7 +44,8 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk, unsigned long parent_rate) { struct socfpga_pll *socfpgaclk = to_socfpga_clk(hwclk); - unsigned long divf, divq, vco_freq, reg; + unsigned long divf, divq, reg; + unsigned long long vco_freq; unsigned long bypass; reg = readl(socfpgaclk->hw.reg); @@ -54,8 +55,9 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk, divf = (reg & SOCFPGA_PLL_DIVF_MASK) >> SOCFPGA_PLL_DIVF_SHIFT; divq = (reg & SOCFPGA_PLL_DIVQ_MASK) >> SOCFPGA_PLL_DIVQ_SHIFT; - vco_freq = parent_rate * (divf + 1); - return vco_freq / (1 + divq); + vco_freq = (unsigned long long)parent_rate * (divf + 1); + do_div(vco_freq, (1 + divq)); + return (unsigned long)vco_freq; } static struct clk_ops clk_pll_ops = {