clk: stratix10: use do_div() for 64-bit calculation
authorDinh Nguyen <dinguyen@kernel.org>
Tue, 14 Jan 2020 16:07:25 +0000 (10:07 -0600)
committerStephen Boyd <sboyd@kernel.org>
Wed, 12 Feb 2020 23:41:28 +0000 (15:41 -0800)
do_div() macro to perform u64 division and guards against overflow if
the result is too large for the unsigned long return type.

Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
Link: https://lkml.kernel.org/r/20200114160726.19771-1-dinguyen@kernel.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/socfpga/clk-pll-s10.c

index 4705eb5..8d7b1d0 100644 (file)
@@ -39,7 +39,9 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk,
        /* read VCO1 reg for numerator and denominator */
        reg = readl(socfpgaclk->hw.reg);
        refdiv = (reg & SOCFPGA_PLL_REFDIV_MASK) >> SOCFPGA_PLL_REFDIV_SHIFT;
-       vco_freq = (unsigned long long)parent_rate / refdiv;
+
+       vco_freq = parent_rate;
+       do_div(vco_freq, refdiv);
 
        /* Read mdiv and fdiv from the fdbck register */
        reg = readl(socfpgaclk->hw.reg + 0x4);