[PATCH 1/2] clk: meson: mpll: fix division by zero in rate_from_params
Martin Blumenstingl
martin.blumenstingl at googlemail.com
Sat Apr 1 06:02:24 PDT 2017
According to the public datasheet all register bits in HHI_MPLL_CNTL7,
HHI_MPLL_CNTL8 and HHI_MPLL_CNTL9 default to zero. On all GX SoCs these
seem to be initialized by the bootloader to some default value.
However, on my Meson8 board they are not initialized, leading to a
division by zero in rate_from_params as the math is:
(parent_rate * SDM_DEN) / ((SDM_DEN * 0) + 0)
Although the rate_from_params function was only introduced recently the
original bug has been there for much longer. It was only exposed
recently when the MPLL clocks were added to the Meson8b clock driver.
Fixes: 1c50da4f27 ("clk: meson: add mpll support")
Signed-off-by: Martin Blumenstingl <martin.blumenstingl at googlemail.com>
---
drivers/clk/meson/clk-mpll.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c
index 540dabe5adad..551aa2a5b291 100644
--- a/drivers/clk/meson/clk-mpll.c
+++ b/drivers/clk/meson/clk-mpll.c
@@ -76,7 +76,12 @@ static unsigned long rate_from_params(unsigned long parent_rate,
unsigned long sdm,
unsigned long n2)
{
- return (parent_rate * SDM_DEN) / ((SDM_DEN * n2) + sdm);
+ unsigned long divisor = (SDM_DEN * n2) + sdm;
+
+ if (divisor == 0)
+ return 0;
+ else
+ return (parent_rate * SDM_DEN) / divisor;
}
static void params_from_rate(unsigned long requested_rate,
--
2.12.1
More information about the linux-amlogic
mailing list