Skip to content

Commit

Permalink
clk: fractional-divider: cast parent_rate to u64 before multiplying
Browse files Browse the repository at this point in the history
On 32bit architectures, like ARM calculating the fractional rate will
do the multiplication before converting the value to u64 when it gets
assigned to ret, which can produce overflows.

The error in question happened with a parent_rate of 386MHz, m = 3000,
n = 60000, which resulted in a wrong rate value of 15812Hz.

Therefore cast parent_rate to u64 to make sure the multiplication
happens in a 64bit space and produces the correct 192MHz in the example.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
  • Loading branch information
Heiko Stübner authored and Mike Turquette committed Sep 10, 2014
1 parent f82a1d1 commit feaefa0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/clk/clk-fractional-divider.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static unsigned long clk_fd_recalc_rate(struct clk_hw *hw,
m = (val & fd->mmask) >> fd->mshift;
n = (val & fd->nmask) >> fd->nshift;

ret = parent_rate * m;
ret = (u64)parent_rate * m;
do_div(ret, n);

return ret;
Expand Down

0 comments on commit feaefa0

Please sign in to comment.