From patchwork Wed May 7 16:24:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 4130561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A22999F23C for ; Wed, 7 May 2014 16:27:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D456720179 for ; Wed, 7 May 2014 16:27:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 D50A42014A for ; Wed, 7 May 2014 16:27:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wi4eF-0005aY-Fj; Wed, 07 May 2014 16:24:47 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wi4eB-0005Hl-G9 for linux-arm-kernel@lists.infradead.org; Wed, 07 May 2014 16:24:44 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N57004N4PKF9W80@mailout1.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 07 May 2014 17:24:15 +0100 (BST) X-AuditID: cbfec7f4-b7fb36d000006ff7-ba-536a5e3169f7 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 6C.BD.28663.13E5A635; Wed, 07 May 2014 17:24:17 +0100 (BST) Received: from AMDC1227.digital.local ([106.116.147.199]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N57003EJPKF5W00@eusync1.samsung.com>; Wed, 07 May 2014 17:24:17 +0100 (BST) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Date: Wed, 07 May 2014 18:24:10 +0200 Message-id: <1399479850-25292-1-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMJMWRmVeSWpSXmKPExsVy+t/xy7qGcVnBBnvWaFlsenyN1eLyrjls Fo9OL2azeDrhIpvF+hmvWRxYPe5c28PmsXlJvUffllWMHk9/7GX2+LxJLoA1issmJTUnsyy1 SN8ugSvj9OVe9oJvnBWnvt9kbWCcxtHFyMkhIWAi0X7/GQuELSZx4d56ti5GLg4hgaWMEv/f 7WUGSQgJ9DFJ/J3iAWKzCahJfG54xAZiiwhoSEzpeswO0sAsMINRouH4A7CEsICTxIppyxhB bBYBVYnPTXfA4rxA8YNTHzNDbJOT+P9yBdMERu4FjAyrGEVTS5MLipPScw31ihNzi0vz0vWS 83M3MUIC4ssOxsXHrA4xCnAwKvHwvojOCBZiTSwrrsw9xCjBwawkwmsclRUsxJuSWFmVWpQf X1Sak1p8iJGJg1OqgVF1idVvluoZ1kr8v+bcZX21VeGqzZ/1GZaLcu+W2q4SXnxZsnBOP+fH c9xT2qP5Pdfx2GhrBGjHmsYrsKQ/+LI1oW5+yZ+kxcrL3V13TfjYcMRu6reyDSuKi2tNnlRE 3baSm+xoVu5U6PTDYonHK6eEyeIXr97rrmIsDb6saPsup8ZDce2JWCWW4oxEQy3mouJEAKp4 gJbmAQAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140507_092443_690428_7A996551 X-CRM114-Status: GOOD ( 10.63 ) X-Spam-Score: -5.7 (-----) Cc: Tomasz Figa , Mike Turquette , linux-kernel@vger.kernel.org, Maxime COQUELIN 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,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 Commit c686078 ("clk: divider: Add round to closest divider") introduced a helper function to check whether given divisor is the best one instead of direct check. However due to int type used instead of unsigned long for passing calculated rates to this function in certain cases an overflow could occur, for example when trying to obtain maximum possible clock rate by calling clk_round_rate(..., UINT_MAX). This patch fixes this issue by changing the type of rate, now and best arguments of the function to unsigned long, which is the type that should be used for clock rates. Signed-off-by: Tomasz Figa Acked-by: Maxime Coquelin --- drivers/clk/clk-divider.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index c572945..e0b360a 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -232,7 +232,7 @@ static int _div_round(struct clk_divider *divider, unsigned long parent_rate, } static bool _is_best_div(struct clk_divider *divider, - int rate, int now, int best) + unsigned long rate, unsigned long now, unsigned long best) { if (divider->flags & CLK_DIVIDER_ROUND_CLOSEST) return abs(rate - now) < abs(rate - best);