Skip to content

Commit

Permalink
clk: fixed-factor: round_rate should use do_div
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Haojian Zhuang authored and Mike Turquette committed Jan 12, 2013
1 parent 4895084 commit bab5330
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/clk/clk-fixed-factor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bab5330

Please sign in to comment.