Skip to contentSkip to conversation

i2c: sirf: Prevent potential division by zero

PATCH In review Axel Lin 2 participants 3 messages Apr 13, 2016

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 i2c: sirf: Prevent potential division by zero

Make sure we don't OOPS in case clock-frequency is set to 0 in a DT. The variable set here is later used as a divisor. Since the clock-frequency property is optional in current code, use SIRFSOC_I2C_DEFAULT_SPEED instead if clock-frequency is set to 0 in a DT.

---
 drivers/i2c/busses/i2c-sirf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-sirf.c +1 -1
index 792a42b..82743e4 100644
@@ -353,7 +353,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
 
 	err = of_property_read_u32(pdev->dev.of_node,
 		"clock-frequency", &bitrate);
-	if (err < 0)
+	if (err < 0 || bitrate == 0)
 		bitrate = SIRFSOC_I2C_DEFAULT_SPEED;
 
 	/*
Signature · 1 line
2.5.0
author
#1 lore raw

PATCH 2/2 i2c: sun6i-p2wi: Prevent potential division by zero

Make sure we don't OOPS in case clock-frequency is set to 0 in a DT. The variable set here is later used as a divisor.

---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/i2c/busses/i2c-sun6i-p2wi.c +5 -0
index 7668e2e..6448291 100644
@@ -202,6 +202,11 @@ static int p2wi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	if (clk_freq == 0) {
+		dev_err(dev, "clock-frequency is set to 0 in DT\n");
+		return -EINVAL;
+	}
+
 	if (of_get_child_count(np) > 1) {
 		dev_err(dev, "P2WI only supports one slave device\n");
 		return -EINVAL;
Signature · 1 line
2.5.0
Acked-by on v1 2/2
#2 lore raw

Re: [RFT][PATCH 2/2] i2c: sun6i-p2wi: Prevent potential division by zero

Quoted 4 lines · On Wed, 13 Apr 2016 08:54:30 +0800 Axel Lin <[email protected]> wrote:

Make sure we don't OOPS in case clock-frequency is set to 0 in a DT. The variable set here is later used as a divisor.

Quoted 20 lines
---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/i2c/busses/i2c-sun6i-p2wi.c +5 -0
index 7668e2e..6448291 100644
@@ -202,6 +202,11 @@ static int p2wi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	if (clk_freq == 0) {
+		dev_err(dev, "clock-frequency is set to 0 in DT\n");
+		return -EINVAL;
+	}
+
 	if (of_get_child_count(np) > 1) {
 		dev_err(dev, "P2WI only supports one slave device\n");
 		return -EINVAL;
Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com