From: Wolfram Sang <wsa@the-dreams.de>
To: linux-i2c@vger.kernel.org
Cc: Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com>,
Axel Lin <axel.lin@ingics.com>, Wolfram Sang <wsa@the-dreams.de>
Subject: [PATCH] i2c: jz4780: really prevent potential division by zero
Date: Fri, 8 Apr 2016 12:03:47 +0200 [thread overview]
Message-ID: <1460109827-3608-1-git-send-email-wsa@the-dreams.de> (raw)
Make sure that 'ret' is populated before we leave and check the variable
which is actually used as a divisor. Add missing '\n' while we are here.
Reported-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Fixes: 34cf2acdafaa ("i2c: jz4780: prevent potential division by zero")
---
drivers/i2c/busses/i2c-jz4780.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index 597408fc6834fc..ba14a863b451f9 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -770,12 +770,17 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
&clk_freq);
- if (ret || clk_freq == 0) {
- dev_err(&pdev->dev, "clock-frequency not specified in DT");
+ if (ret) {
+ dev_err(&pdev->dev, "clock-frequency not specified in DT\n");
goto err;
}
i2c->speed = clk_freq / 1000;
+ if (i2c->speed == 0) {
+ ret = -EINVAL;
+ dev_err(&pdev->dev, "clock-frequency minimum is 1000\n");
+ goto err;
+ }
jz4780_i2c_set_speed(i2c);
dev_info(&pdev->dev, "Bus frequency is %d KHz\n", i2c->speed);
--
2.7.0
next reply other threads:[~2016-04-08 10:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-08 10:03 Wolfram Sang [this message]
2016-04-08 23:42 ` [PATCH] i2c: jz4780: really prevent potential division by zero Axel Lin
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=1460109827-3608-1-git-send-email-wsa@the-dreams.de \
--to=wsa@the-dreams.de \
--cc=Zubair.Kakakhel@imgtec.com \
--cc=axel.lin@ingics.com \
--cc=linux-i2c@vger.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;
as well as URLs for NNTP newsgroup(s).