mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: nixiaoming <nixiaoming@huawei.com>
To: <mturquette@baylibre.com>, <sboyd@kernel.org>,
	<nixiaoming@huawei.com>, <chao.xie@marvell.com>
Cc: <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] clk:mmp: clk-mix.c fix divide-by-zero
Date: Fri, 29 Mar 2019 19:46:00 +0800	[thread overview]
Message-ID: <1553859960-31501-1-git-send-email-nixiaoming@huawei.com> (raw)

The _get_div function has a branch with a return value of 0
Add a check on the return value of _get_div to avoid divide-by-zero

Signed-off-by: nixiaoming <nixiaoming@huawei.com>
---
 drivers/clk/mmp/clk-mix.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index 90814b2..9d152c2 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -245,6 +245,8 @@ static int mmp_clk_mix_determine_rate(struct clk_hw *hw,
 			div_val_max = _get_maxdiv(mix);
 			for (j = 0; j < div_val_max; j++) {
 				div = _get_div(mix, j);
+				if (!div) /* avoid divide-by-zero */
+					continue;
 				mix_rate = parent_rate / div;
 				gap = abs(mix_rate - req->rate);
 				if (!parent_best || gap < gap_best) {
@@ -341,6 +343,8 @@ static unsigned long mmp_clk_mix_recalc_rate(struct clk_hw *hw,
 	shift = mix->reg_info.shift_div;
 
 	div = _get_div(mix, MMP_CLK_BITS_GET_VAL(mux_div, width, shift));
+	if (!div) /* avoid divide-by-zero */
+		return -EINVAL;
 
 	return parent_rate / div;
 }
-- 
1.8.5.6


             reply	other threads:[~2019-03-29 11:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29 11:46 nixiaoming [this message]
2019-03-29 12:41 ` Mukesh Ojha
2019-03-29 22:48 ` Stephen Boyd
2019-03-30  2:20   ` Nixiaoming

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=1553859960-31501-1-git-send-email-nixiaoming@huawei.com \
    --to=nixiaoming@huawei.com \
    --cc=chao.xie@marvell.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®