提交 5c2f117a 编写于 作者: E Emil Lundmark 提交者: Stephen Boyd

clk: imx: fix integer overflow in AV PLL round rate

Since 'parent_rate * mfn' may overflow 32 bits, the result should be
stored using 64 bits.

The problem was discovered when trying to set the rate of the audio PLL
(pll4_post_div) on an i.MX6Q. The desired rate was 196.608 MHz, but
the actual rate returned was 192.000570 MHz. The round rate function should
have been able to return 196.608 MHz, i.e., the desired rate.

Fixes: ba7f4f55 ("clk: imx: correct AV PLL rate formula")
Cc: Anson Huang <b20788@freescale.com>
Signed-off-by: NEmil Lundmark <emil@limesaudio.com>
Reviewed-by: NFabio Estevam <fabio.estevam@nxp.com>
Acked-by: NShawn Guo <shawnguo@kernel.org>
Signed-off-by: NStephen Boyd <sboyd@codeaurora.org>
上级 06b113e9
...@@ -223,7 +223,7 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw, ...@@ -223,7 +223,7 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
temp64 *= mfn; temp64 *= mfn;
do_div(temp64, mfd); do_div(temp64, mfd);
return (parent_rate * div) + (u32)temp64; return parent_rate * div + (unsigned long)temp64;
} }
static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate, static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
...@@ -247,7 +247,11 @@ static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate, ...@@ -247,7 +247,11 @@ static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
do_div(temp64, parent_rate); do_div(temp64, parent_rate);
mfn = temp64; mfn = temp64;
return parent_rate * div + parent_rate * mfn / mfd; temp64 = (u64)parent_rate;
temp64 *= mfn;
do_div(temp64, mfd);
return parent_rate * div + (unsigned long)temp64;
} }
static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate, static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册