]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
clk: meson: mpll: use 64bit math in rate_from_params
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Sat, 1 Apr 2017 13:02:25 +0000 (15:02 +0200)
committerJerome Brunet <jbrunet@baylibre.com>
Fri, 7 Apr 2017 15:45:30 +0000 (17:45 +0200)
On Meson8b the MPLL parent clock (fixed_pll) has a rate of 2550MHz.
Multiplying this with SDM_DEN results in a value greater than 32bits.
This is not a problem on the 64bit Meson GX SoCs, but it may result in
undefined behavior on the older 32bit Meson8b SoC.

While rate_from_params was only introduced recently to make the math
reusable from _round_rate and _recalc_rate the original bug exists much
longer.

Fixes: 1c50da4f27 ("clk: meson: add mpll support")
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
[as discussed on the ml, use DIV_ROUND_UP_ULL]
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
drivers/clk/meson/clk-mpll.c

index d9462b505dcca910fce064ba47c51c003ac3e4da..39eab69fe51a8a76791029ae718c575f16843630 100644 (file)
@@ -79,7 +79,7 @@ static long rate_from_params(unsigned long parent_rate,
        if (n2 < N2_MIN)
                return -EINVAL;
 
-       return (parent_rate * SDM_DEN) / divisor;
+       return DIV_ROUND_UP_ULL((u64)parent_rate * SDM_DEN, divisor);
 }
 
 static void params_from_rate(unsigned long requested_rate,