diff mbox

i2c: jz4780: Return error if clk_freq is set to 0

Message ID 1460102372.5233.1.camel@ingics.com
State Superseded
Headers show

Commit Message

Axel Lin April 8, 2016, 7:59 a.m. UTC
Current code returns 0 in probe if clk_freq is set to 0.
As a result, the probe success but the module does not work. Fix it.

Fixes: 34cf2acdafaa ("i2c: jz4780: prevent potential division by zero")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/i2c/busses/i2c-jz4780.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Wolfram Sang April 8, 2016, 9:55 a.m. UTC | #1
On Fri, Apr 08, 2016 at 03:59:32PM +0800, Axel Lin wrote:
> Current code returns 0 in probe if clk_freq is set to 0.
> As a result, the probe success but the module does not work. Fix it.
> 
> Fixes: 34cf2acdafaa ("i2c: jz4780: prevent potential division by zero")
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

True, thanks for the pointer! However, I think we should also check
i2c->speed directly. I'll send a patch right now. Please let me know if
you agree on that one.
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index 597408f..0b3ba8d 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -772,6 +772,8 @@  static int jz4780_i2c_probe(struct platform_device *pdev)
 				   &clk_freq);
 	if (ret || clk_freq == 0) {
 		dev_err(&pdev->dev, "clock-frequency not specified in DT");
+		if (ret == 0)
+			ret = -EINVAL;
 		goto err;
 	}