Skip to content

Commit f7b7d30

Browse files
Devi Priyaandersson
authored andcommitted
clk: qcom: clk-rcg2: Fix clock rate overflow for high parent frequencies
If the parent clock rate is greater than unsigned long max/2 then integer overflow happens when calculating the clock rate on 32-bit systems. As RCG2 uses half integer dividers, the clock rate is first being multiplied by 2 which will overflow the unsigned long max value. Hence, replace the common pattern of doing 64-bit multiplication and then a do_div() call with simpler mult_frac call. Fixes: bcd61c0 ("clk: qcom: Add support for root clock generators (RCGs)") Signed-off-by: Devi Priya <[email protected]> Reviewed-by: Marijn Suijten <[email protected]> Link: https://lore.kernel.org/r/[email protected] [bjorn: Also drop unnecessary {} around single statements] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 4afda5f commit f7b7d30

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

drivers/clk/qcom/clk-rcg2.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,11 @@ static int clk_rcg2_set_parent(struct clk_hw *hw, u8 index)
158158
static unsigned long
159159
calc_rate(unsigned long rate, u32 m, u32 n, u32 mode, u32 hid_div)
160160
{
161-
if (hid_div) {
162-
rate *= 2;
163-
rate /= hid_div + 1;
164-
}
161+
if (hid_div)
162+
rate = mult_frac(rate, 2, hid_div + 1);
165163

166-
if (mode) {
167-
u64 tmp = rate;
168-
tmp *= m;
169-
do_div(tmp, n);
170-
rate = tmp;
171-
}
164+
if (mode)
165+
rate = mult_frac(rate, m, n);
172166

173167
return rate;
174168
}

0 commit comments

Comments
 (0)