提交 6132e89a 编写于 作者: Y Yibo Cai 提交者: Michael Turquette

clk: atlas7: fix integer overflow in dto rate calculation

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: NYibo Cai <yibo.cai@csr.com>
Signed-off-by: NBarry Song <Baohua.Song@csr.com>
Signed-off-by: NStephen Boyd <sboyd@codeaurora.org>
上级 b1062298
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册