提交 a1932ece 编写于 作者: P Priyanka Singh 提交者: Priyanka Jain

drivers: ddr: util.c: Fix divide by zero issue

Fix possible divide by zero issue in get_memory_clk_period_ps
by adding a check
Signed-off-by: NPriyanka Singh <priyanka.singh@nxp.com>
Reviewed-by: NPriyanka Jain <priyanka.jain@nxp.com>
上级 f8ed9059
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright 2008-2014 Freescale Semiconductor, Inc. * Copyright 2008-2014 Freescale Semiconductor, Inc.
* Copyright 2021 NXP
*/ */
#include <common.h> #include <common.h>
...@@ -75,10 +76,13 @@ unsigned int get_memory_clk_period_ps(const unsigned int ctrl_num) ...@@ -75,10 +76,13 @@ unsigned int get_memory_clk_period_ps(const unsigned int ctrl_num)
/* Round to nearest 10ps, being careful about 64-bit multiply/divide */ /* Round to nearest 10ps, being careful about 64-bit multiply/divide */
unsigned long long rem, mclk_ps = ULL_2E12; unsigned long long rem, mclk_ps = ULL_2E12;
if (data_rate) {
/* Now perform the big divide, the result fits in 32-bits */ /* Now perform the big divide, the result fits in 32-bits */
rem = do_div(mclk_ps, data_rate); rem = do_div(mclk_ps, data_rate);
result = (rem >= (data_rate >> 1)) ? mclk_ps + 1 : mclk_ps; result = (rem >= (data_rate >> 1)) ? mclk_ps + 1 : mclk_ps;
} else {
result = 0;
}
return result; return result;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册