Skip to content

Commit 00f8f70

Browse files
Gax-cbebarino
authored andcommitted
clk: sophgo: avoid integer overflow in sg2042_pll_recalc_rate()
This was found by a static analyzer. There may be a potential integer overflow issue in sg2042_pll_recalc_rate(). numerator is defined as u64 while parent_rate is defined as unsigned long and ctrl_table.fbdiv is defined as unsigned int. On 32-bit machine, the result of the calculation will be limited to "u32" without correct casting. Integer overflow may occur on high-performance systems. Fixes: 48cf7e0 ("clk: sophgo: Add SG2042 clock driver") Signed-off-by: Zichen Xie <[email protected]> Reviewed-by: Chen Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Dan Carpenter <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent b961b65 commit 00f8f70

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/clk/sophgo/clk-sg2042-pll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static unsigned long sg2042_pll_recalc_rate(unsigned int reg_value,
153153

154154
sg2042_pll_ctrl_decode(reg_value, &ctrl_table);
155155

156-
numerator = parent_rate * ctrl_table.fbdiv;
156+
numerator = (u64)parent_rate * ctrl_table.fbdiv;
157157
denominator = ctrl_table.refdiv * ctrl_table.postdiv1 * ctrl_table.postdiv2;
158158
do_div(numerator, denominator);
159159
return numerator;

0 commit comments

Comments
 (0)