Skip to contentSkip to conversation

i2c: efm32: Prevent potential division by zero

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

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 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.

---
 drivers/i2c/busses/i2c-efm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-efm32.c +1 -1
index 8eff627..394c695 100644
@@ -389,7 +389,7 @@ static int efm32_i2c_probe(struct platform_device *pdev)
 	ddata->location = location;
 
 	ret = of_property_read_u32(np, "clock-frequency", &frequency);
-	if (!ret) {
+	if (!ret && frequency != 0) {
 		dev_dbg(&pdev->dev, "using frequency %u\n", frequency);
 	} else {
 		frequency = 100000;
Signature · 1 line
2.5.0
#1 lore raw

Hello Axel,

Quoted 2 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.

This is correct in principle. I thought it's ok to misbehave if the DT is broken? In this case the current code is just fine.

Best regards
Uwe

Quoted 13 lines
drivers/i2c/busses/i2c-efm32.c +1 -1
index 8eff627..394c695 100644
@@ -389,7 +389,7 @@ static int efm32_i2c_probe(struct platform_device *pdev)
 	ddata->location = location;
 
 	ret = of_property_read_u32(np, "clock-frequency", &frequency);
-	if (!ret) {
+	if (!ret && frequency != 0) {
 		dev_dbg(&pdev->dev, "using frequency %u\n", frequency);
 	} else {
 		frequency = 100000;
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#2 lore raw

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

Quoted 8 lines

Hello Axel,

Quoted 2 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.

This is correct in principle. I thought it's ok to misbehave if the DT is broken? In this case the current code is just fine.

Current code hit division by zero if clock-frequency is 0. clkdiv = DIV_ROUND_UP(rate, 8 * ddata->frequency) - 1; Is it ok?

#3 lore raw

Hello Axel,

Quoted 11 lines · Axel Lin

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

Quoted 6 lines · Axel Lin
Quoted 2 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.

This is correct in principle. I thought it's ok to misbehave if the DT is broken? In this case the current code is just fine.

Current code hit division by zero if clock-frequency is 0. clkdiv = DIV_ROUND_UP(rate, 8 * ddata->frequency) - 1; Is it ok?

IMHO yes. If you give the kernel a broken dt it's ok that the kernel is broken then.

So if you want, take my:

Registered-but-considered-unimportant-by Uwe Kleine-König <[email protected]>

:-)

Best regards
Uwe

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