From: Beniamin Bia <beniamin.bia@analog.com>
To: <jic23@kernel.org>
Cc: <lars@metafoo.de>, <Michael.Hennerich@analog.com>,
<pmeerw@pmeerw.net>, <linux-iio@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <biabeniamin@outlook.com>,
<knaack.h@gmx.de>,
Michael Hennerich <michael.hennerich@analog.com>,
Beniamin Bia <beniamin.bia@analog.com>
Subject: [PATCH] iio: frequency: adf4371: Fix divide by zero exception bug
Date: Tue, 7 Jan 2020 15:15:59 +0200 [thread overview]
Message-ID: <20200107131559.17772-1-beniamin.bia@analog.com> (raw)
From: Michael Hennerich <michael.hennerich@analog.com>
During initialization adf4371_pll_fract_n_get_rate() is called on all
output channels to determine if the device was setup. In this case
mod2 is zero which can cause a divide by zero exception.
Return before that can happen.
Fixes: 7f699bd149134 ("iio: frequency: adf4371: Add support for ADF4371 PLL")
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
drivers/iio/frequency/adf4371.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
index e2a599b912e5..c21462238314 100644
--- a/drivers/iio/frequency/adf4371.c
+++ b/drivers/iio/frequency/adf4371.c
@@ -191,6 +191,9 @@ static unsigned long long adf4371_pll_fract_n_get_rate(struct adf4371_state *st,
unsigned long long val, tmp;
unsigned int ref_div_sel;
+ if (st->mod2 == 0)
+ return 0;
+
val = (((u64)st->integer * ADF4371_MODULUS1) + st->fract1) * st->fpfd;
tmp = (u64)st->fract2 * st->fpfd;
do_div(tmp, st->mod2);
--
2.17.1
next reply other threads:[~2020-01-07 13:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 13:15 Beniamin Bia [this message]
2020-01-11 11:08 ` [PATCH] iio: frequency: adf4371: Fix divide by zero exception bug Jonathan Cameron
2020-01-14 16:19 ` Hennerich, Michael
2020-01-18 11:29 ` Jonathan Cameron
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=20200107131559.17772-1-beniamin.bia@analog.com \
--to=beniamin.bia@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=biabeniamin@outlook.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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.