summaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
authorYibo Cai <yibo.cai@csr.com>2015-08-04 16:45:28 +0200
committerMichael Turquette <mturquette@baylibre.com>2015-08-25 01:49:06 +0200
commit6132e89aef51df044246b5aef822144217794ae1 (patch)
treea4fe32bdd7218f86792eb8b5d26daa2de417200b /drivers/clk
parentclk: atlas7: export mux clks so that consumers can get them (diff)
downloadlinux-6132e89aef51df044246b5aef822144217794ae1.tar.xz
linux-6132e89aef51df044246b5aef822144217794ae1.zip
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: Yibo Cai <yibo.cai@csr.com> Signed-off-by: Barry Song <Baohua.Song@csr.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/sirf/clk-atlas7.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/clk/sirf/clk-atlas7.c b/drivers/clk/sirf/clk-atlas7.c
index 07b970ff50f1..ed77fd51692c 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);