aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Lundmark <emil@limesaudio.com>2016-10-12 06:31:40 -0400
committerStephen Boyd <sboyd@codeaurora.org>2016-11-01 20:07:54 -0400
commit5c2f117a22e46a4afee6ddee29b653a7a2a6b41f (patch)
treea752154c1f8464c9beb7cfc07333bfa4d52bbcff
parent06b113e9f28f8657715919087a3f54b77d1634ed (diff)
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: ba7f4f557eb6 ("clk: imx: correct AV PLL rate formula") Cc: Anson Huang <b20788@freescale.com> Signed-off-by: Emil Lundmark <emil@limesaudio.com> Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com> Acked-by: Shawn Guo <shawnguo@kernel.org> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r--drivers/clk/imx/clk-pllv3.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index 19f9b622981a..7a6acc3e4a92 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -223,7 +223,7 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
223 temp64 *= mfn; 223 temp64 *= mfn;
224 do_div(temp64, mfd); 224 do_div(temp64, mfd);
225 225
226 return (parent_rate * div) + (u32)temp64; 226 return parent_rate * div + (unsigned long)temp64;
227} 227}
228 228
229static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate, 229static 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 do_div(temp64, parent_rate); 247 do_div(temp64, parent_rate);
248 mfn = temp64; 248 mfn = temp64;
249 249
250 return parent_rate * div + parent_rate * mfn / mfd; 250 temp64 = (u64)parent_rate;
251 temp64 *= mfn;
252 do_div(temp64, mfd);
253
254 return parent_rate * div + (unsigned long)temp64;
251} 255}
252 256
253static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate, 257static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,