Skip to contentSkip to conversation

i2c: efm32: Prevent potential division by zero

PATCH In review Axel Lin 2 participants 4 messages Apr 14, 2016 I2C subsystem host drivers

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v2 1/1 i2c: efm32: 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.

---
Hi Uwe,
If my understand is correct, you prefer to make it return error rather than using default frequency setting if DT setting is wrong.

v2: Make probe return error instead of using default frequency.

 drivers/i2c/busses/i2c-efm32.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-efm32.c +7 -0
index 8eff627..7c0636e 100644
@@ -395,6 +395,13 @@ static int efm32_i2c_probe(struct platform_device *pdev)
 		frequency = 100000;
 		dev_info(&pdev->dev, "defaulting to 100 kHz\n");
 	}
+
+	if (frequency == 0) {
+		dev_err(&pdev->dev, "Invalid clock-frequency\n");
+		ret = -EINVAL;
+		goto err_disable_clk;
+	}
+
 	ddata->frequency = frequency;
 
 	rate = clk_get_rate(ddata->clk);
Signature · 1 line
2.5.0
#1 lore raw

Hello Axel,

Quoted 7 lines · Axel Lin

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.

---
If my understand is correct, you prefer to make it return error rather than using default frequency setting if DT setting is wrong.

No, I'd say it doesn't matter that the driver crashes if something invalid is specified in the device tree. This is not a driver bug, but a dt bug. So if it happens, fix the device tree, no need to modify the driver.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#2 lore raw

2016-04-14 19:40 GMT+08:00 Uwe Kleine-König <[email protected]>:

Quoted 11 lines

Hello Axel,

Quoted 7 lines · Axel Lin

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.

---
If my understand is correct, you prefer to make it return error rather than using default frequency setting if DT setting is wrong.

Quoted 4 lines

No, I'd say it doesn't matter that the driver crashes if something invalid is specified in the device tree. This is not a driver bug, but a dt bug. So if it happens, fix the device tree, no need to modify the driver.

I know that such case is a DT bug.
But the intention of this patch is to avoid oops rather than fix dt. Make probe return error is enough to inform developer fixing dt.

#3 lore raw

Hello Axel,

Quoted 10 lines · Axel Lin

2016-04-14 19:40 GMT+08:00 Uwe Kleine-König <[email protected]>:

Quoted 9 lines · Axel Lin
Quoted 7 lines

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.

---
If my understand is correct, you prefer to make it return error rather than using default frequency setting if DT setting is wrong.

Quoted 8 lines
Quoted 4 lines

No, I'd say it doesn't matter that the driver crashes if something invalid is specified in the device tree. This is not a driver bug, but a dt bug. So if it happens, fix the device tree, no need to modify the driver.

I know that such case is a DT bug.
But the intention of this patch is to avoid oops rather than fix dt. Make probe return error is enough to inform developer fixing dt.

an oops is also enough, and maybe even better because $developer cannot miss it.

I don't care much, because the error probably won't happen. If you ask me, I like your v2 better.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |