i2c: efm32: Prevent potential division by zero
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
@@ -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
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@@ -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/ |
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?
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:
:-)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |