From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
To: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org,
jbrunet@baylibre.com, sboyd@codeaurora.org,
mturquette@baylibre.com, narmstrong@baylibre.com
Cc: linux-arm-kernel@lists.infradead.org, khilman@baylibre.com,
carlo@caione.org,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Subject: [PATCH 1/2] clk: meson: mpll: fix division by zero in rate_from_params
Date: Sat, 1 Apr 2017 15:02:24 +0200 [thread overview]
Message-ID: <20170401130225.8811-2-martin.blumenstingl@googlemail.com> (raw)
In-Reply-To: <20170401130225.8811-1-martin.blumenstingl@googlemail.com>
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@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
WARNING: multiple messages have this Message-ID (diff)
From: martin.blumenstingl@googlemail.com (Martin Blumenstingl)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] clk: meson: mpll: fix division by zero in rate_from_params
Date: Sat, 1 Apr 2017 15:02:24 +0200 [thread overview]
Message-ID: <20170401130225.8811-2-martin.blumenstingl@googlemail.com> (raw)
In-Reply-To: <20170401130225.8811-1-martin.blumenstingl@googlemail.com>
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@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
WARNING: multiple messages have this Message-ID (diff)
From: martin.blumenstingl@googlemail.com (Martin Blumenstingl)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 1/2] clk: meson: mpll: fix division by zero in rate_from_params
Date: Sat, 1 Apr 2017 15:02:24 +0200 [thread overview]
Message-ID: <20170401130225.8811-2-martin.blumenstingl@googlemail.com> (raw)
In-Reply-To: <20170401130225.8811-1-martin.blumenstingl@googlemail.com>
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@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
next prev parent reply other threads:[~2017-04-01 13:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-01 13:02 [PATCH 0/2] clk: meson: MPLL fixes for Meson8b Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl [this message]
2017-04-01 13:02 ` [PATCH 1/2] clk: meson: mpll: fix division by zero in rate_from_params Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl
2017-04-02 14:49 ` Jerome Brunet
2017-04-02 14:49 ` Jerome Brunet
2017-04-02 14:49 ` Jerome Brunet
2017-04-02 18:43 ` Martin Blumenstingl
2017-04-02 18:43 ` Martin Blumenstingl
2017-04-02 18:43 ` Martin Blumenstingl
2017-04-02 21:34 ` Jerome Brunet
2017-04-02 21:34 ` Jerome Brunet
2017-04-02 21:34 ` Jerome Brunet
2017-04-07 15:12 ` Jerome Brunet
2017-04-07 15:12 ` Jerome Brunet
2017-04-07 15:12 ` Jerome Brunet
2017-04-01 13:02 ` [PATCH 2/2] clk: meson: mpll: use 64bit math " Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl
2017-04-01 13:02 ` Martin Blumenstingl
2017-04-02 15:09 ` Jerome Brunet
2017-04-02 15:09 ` Jerome Brunet
2017-04-02 15:09 ` Jerome Brunet
2017-04-02 18:46 ` Martin Blumenstingl
2017-04-02 18:46 ` Martin Blumenstingl
2017-04-02 18:46 ` Martin Blumenstingl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170401130225.8811-2-martin.blumenstingl@googlemail.com \
--to=martin.blumenstingl@googlemail.com \
--cc=carlo@caione.org \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=narmstrong@baylibre.com \
--cc=sboyd@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.