diff mbox

i2c: jz4780: really prevent potential division by zero

Message ID 1460109827-3608-1-git-send-email-wsa@the-dreams.de
State Accepted
Headers show

Commit Message

Wolfram Sang April 8, 2016, 10:03 a.m. UTC
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(-)

Comments

Axel Lin April 8, 2016, 11:42 p.m. UTC | #1
2016-04-08 18:03 GMT+08:00 Wolfram Sang <wsa@the-dreams.de>:
> 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")

Looks good to me.
Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);