Skip to content

Commit

Permalink
i2c: jz4780: really prevent potential division by zero
Browse files Browse the repository at this point in the history
Make sure we avoid a division-by-zero OOPS in case clock-frequency is
set too low in DT. Add missing '\n' while we are here.

Signed-off-by: Wolfram Sang <[email protected]>
Acked-by: Axel Lin <[email protected]>
  • Loading branch information
Wolfram Sang committed Apr 9, 2016
1 parent 4ececb7 commit caf2808
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/i2c/busses/i2c-jz4780.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,11 +771,16 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
&clk_freq);
if (ret) {
dev_err(&pdev->dev, "clock-frequency not specified in DT");
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);
Expand Down

0 comments on commit caf2808

Please sign in to comment.