i2c: uniphier: error out if bus speed is zero
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Mon, 30 Nov 2015 09:53:34 +0000 (18:53 +0900)
committerWolfram Sang <wsa@the-dreams.de>
Mon, 14 Dec 2015 09:59:05 +0000 (10:59 +0100)
There is code to divide by "bus_speed" some lines below.
To eliminate the possibility of division by zero, bail out if
"clock-frequency" is specified as zero.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/busses/i2c-uniphier.c

index 2b2c20b3a57a3165bbf7dd89531265bdc27a7926..1f4f3f53819c7a88516dad5eab11d773fceb89f9 100644 (file)
@@ -327,6 +327,11 @@ static int uniphier_i2c_clk_init(struct device *dev,
        if (of_property_read_u32(np, "clock-frequency", &bus_speed))
                bus_speed = UNIPHIER_I2C_DEFAULT_SPEED;
 
+       if (!bus_speed) {
+               dev_err(dev, "clock-freqyency should not be zero\n");
+               return -EINVAL;
+       }
+
        if (bus_speed > UNIPHIER_I2C_MAX_SPEED)
                bus_speed = UNIPHIER_I2C_MAX_SPEED;