clk: fixed-factor: round_rate should use do_div
authorHaojian Zhuang <haojian.zhuang@gmail.com>
Mon, 3 Dec 2012 08:14:37 +0000 (16:14 +0800)
committerMike Turquette <mturquette@linaro.org>
Sat, 12 Jan 2013 02:43:27 +0000 (18:43 -0800)
clk->rate = parent->rate / div * mult

The formula is OK. But it may overflow while we do operate with
unsigned long. So use do_div instead.

Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
[mturquette@linaro.org: improved $SUBJECT]

drivers/clk/clk-fixed-factor.c

index a4899855c0f675bcc87a37adb40a56d6ae2b609b..1ef271e47594a318b04f5860ac03244e969df5aa 100644 (file)
@@ -28,8 +28,11 @@ static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,
                unsigned long parent_rate)
 {
        struct clk_fixed_factor *fix = to_clk_fixed_factor(hw);
+       unsigned long long int rate;
 
-       return parent_rate * fix->mult / fix->div;
+       rate = (unsigned long long int)parent_rate * fix->mult;
+       do_div(rate, fix->div);
+       return (unsigned long)rate;
 }
 
 static long clk_factor_round_rate(struct clk_hw *hw, unsigned long rate,