From: 21cnbao@gmail.com (Barry Song)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/7] clk: sirf: fix integer overflow in dto rate calculation
Date: Tue, 28 Jul 2015 06:27:21 +0000 [thread overview]
Message-ID: <1438064845-17894-4-git-send-email-21cnbao@gmail.com> (raw)
In-Reply-To: <1438064845-17894-1-git-send-email-21cnbao@gmail.com>
From: Yibo Cai <yibo.cai@csr.com>
I cannot believe that I spend quite a lot time in finding this bug.
It seems a pitfall people tend to fall in.
In "int64 = int32 * int32", conversion from 32-bits to 64-bits comes
after the multiplication. So this statement may not work as expected.
Signed-off-by: Yibo Cai <yibo.cai@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
---
drivers/clk/sirf/clk-atlas7.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/sirf/clk-atlas7.c b/drivers/clk/sirf/clk-atlas7.c
index d01dce3..cf489a5 100644
--- a/drivers/clk/sirf/clk-atlas7.c
+++ b/drivers/clk/sirf/clk-atlas7.c
@@ -519,7 +519,7 @@ static unsigned long dto_clk_recalc_rate(struct clk_hw *hw,
static long dto_clk_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *parent_rate)
{
- u64 dividend = rate * (1 << 29);
+ u64 dividend = (u64)rate * (1 << 29);
do_div(dividend, *parent_rate);
dividend *= *parent_rate;
@@ -531,7 +531,7 @@ static long dto_clk_round_rate(struct clk_hw *hw, unsigned long rate,
static int dto_clk_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
- u64 dividend = rate * (1 << 29);
+ u64 dividend = (u64)rate * (1 << 29);
struct clk_dto *clk = to_dtoclk(hw);
do_div(dividend, parent_rate);
--
1.9.1
next prev parent reply other threads:[~2015-07-28 6:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-28 6:27 [PATCH 0/7] clk: atlas7: a bind of fixes Barry Song
2015-07-28 6:27 ` [PATCH 1/7] clk: atlas7: add lost pwm unit clks Barry Song
2015-07-28 6:27 ` [PATCH 2/7] clk: atlas7: export mux clks so that driver can use it Barry Song
2015-07-28 21:56 ` Stephen Boyd
2015-07-29 12:24 ` Barry Song
2015-07-28 6:27 ` Barry Song [this message]
2015-07-28 6:27 ` [PATCH 4/7] clk: atlas7: replace dto resolution magic number by macro Barry Song
2015-07-28 6:27 ` [PATCH 5/7] clk: atlas7: fix the clock tree for bluetooth stuff Barry Song
2015-07-28 22:07 ` Stephen Boyd
2015-07-29 14:52 ` Barry Song
2015-08-06 1:44 ` Stephen Boyd
2015-08-06 9:53 ` Barry Song
2015-08-10 2:35 ` Barry Song
2015-08-12 0:02 ` Stephen Boyd
2015-08-12 2:39 ` Barry Song
2015-07-28 6:27 ` [PATCH 6/7] clk: sirf: fix bit field and its root clk for coresight_tpiu Barry Song
2015-07-28 6:27 ` [PATCH 7/7] clk: atlas7: fix pll missed divide NR in fraction mode Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438064845-17894-4-git-send-email-21cnbao@gmail.com \
--to=21cnbao@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).