All of lore.kernel.org
 help / color / mirror / Atom feed
From: Giulio Benetti <giulio.benetti@benettiengineering.com>
To: u-boot@lists.denx.de
Subject: [PATCH 1/3] clk: imx: pllv3: fix potential 'divide by zero' in sys_get_rate()
Date: Fri, 17 Jan 2020 12:01:59 +0100	[thread overview]
Message-ID: <20200117110201.15959-2-giulio.benetti@benettiengineering.com> (raw)
In-Reply-To: <20200117110201.15959-1-giulio.benetti@benettiengineering.com>

Guard 'parent_rate==0' to prevent 'divide by zero' issue in
clk_pplv3_sys_get_rate(). Also, guard 'parent_rate<0' that would mean
that clk_get_parent_rate() returned an error, so better to return
early with error EINVAL.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
 drivers/clk/imx/clk-pllv3.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index fc16416d5f..0d8e39cfbb 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -121,10 +121,16 @@ static ulong clk_pllv3_sys_set_rate(struct clk *clk, ulong rate)
 {
 	struct clk_pllv3 *pll = to_clk_pllv3(clk);
 	unsigned long parent_rate = clk_get_parent_rate(clk);
-	unsigned long min_rate = parent_rate * 54 / 2;
-	unsigned long max_rate = parent_rate * 108 / 2;
+	unsigned long min_rate;
+	unsigned long max_rate;
 	u32 val, div;
 
+	if (parent_rate <= 0)
+		return -EINVAL;
+
+	min_rate = parent_rate * 54 / 2;
+	max_rate = parent_rate * 108 / 2;
+
 	if (rate < min_rate || rate > max_rate)
 		return -EINVAL;
 
-- 
2.20.1

  reply	other threads:[~2020-01-17 11:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17 11:01 [PATCH 0/3] fix pllv3 defects reported by Coverity Giulio Benetti
2020-01-17 11:01 ` Giulio Benetti [this message]
2020-01-17 11:30   ` [PATCH 1/3] clk: imx: pllv3: fix potential 'divide by zero' in sys_get_rate() Adam Ford
2020-01-17 11:49     ` Giulio Benetti
2020-01-17 12:06     ` [PATCH v2 0/3] fix pllv3 defects reported by Coverity Giulio Benetti
2020-01-17 12:06       ` [PATCH v2 1/3] clk: imx: pllv3: fix potential 'divide by zero' in sys_get_rate() Giulio Benetti
2020-01-17 12:06       ` [PATCH v2 2/3] clk: imx: pllv3: fix potential 'divide by zero' in av_get_rate() Giulio Benetti
2020-01-17 12:06       ` [PATCH v2 3/3] clk: imx: pllv3: fix potential 'divide by zero' in av_set_rate() Giulio Benetti
2020-01-26 19:36       ` [PATCH v2 0/3] fix pllv3 defects reported by Coverity Giulio Benetti
2020-01-17 11:02 ` [PATCH 2/3] clk: imx: pllv3: fix potential 'divide by zero' in av_get_rate() Giulio Benetti
2020-01-17 11:02 ` [PATCH 3/3] clk: imx: pllv3: fix potential 'divide by zero' in av_set_rate() Giulio Benetti

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=20200117110201.15959-2-giulio.benetti@benettiengineering.com \
    --to=giulio.benetti@benettiengineering.com \
    --cc=u-boot@lists.denx.de \
    /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.