Commit b609338b authored by Martin Blumenstingl's avatar Martin Blumenstingl Committed by Jerome Brunet

clk: meson: mpll: use 64bit math in rate_from_params

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: 1c50da4f ("clk: meson: add mpll support")
Reviewed-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Signed-off-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
[as discussed on the ml, use DIV_ROUND_UP_ULL]
Signed-off-by: default avatarJerome Brunet <jbrunet@baylibre.com>
parent 88e4ac68
...@@ -79,7 +79,7 @@ static long rate_from_params(unsigned long parent_rate, ...@@ -79,7 +79,7 @@ static long rate_from_params(unsigned long parent_rate,
if (n2 < N2_MIN) if (n2 < N2_MIN)
return -EINVAL; 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, static void params_from_rate(unsigned long requested_rate,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment