All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: efm32: Prevent potential division by zero
@ 2016-04-14  7:42 Axel Lin
  2016-04-14  8:24 ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-14  7:42 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Uwe Kleine-König, linux-i2c

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.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/i2c/busses/i2c-efm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
index 8eff627..394c695 100644
--- a/drivers/i2c/busses/i2c-efm32.c
+++ b/drivers/i2c/busses/i2c-efm32.c
@@ -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;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: efm32: Prevent potential division by zero
  2016-04-14  7:42 [PATCH] i2c: efm32: Prevent potential division by zero Axel Lin
@ 2016-04-14  8:24 ` Uwe Kleine-König
  2016-04-14  8:29   ` Axel Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2016-04-14  8:24 UTC (permalink / raw)
  To: Axel Lin; +Cc: Wolfram Sang, linux-i2c, Uwe Kleine-König

Hello Axel,

On Thu, Apr 14, 2016 at 03:42:54PM +0800, Axel Lin 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.

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

> diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
> index 8eff627..394c695 100644
> --- a/drivers/i2c/busses/i2c-efm32.c
> +++ b/drivers/i2c/busses/i2c-efm32.c
> @@ -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;

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: efm32: Prevent potential division by zero
  2016-04-14  8:24 ` Uwe Kleine-König
@ 2016-04-14  8:29   ` Axel Lin
  2016-04-14  9:06     ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-14  8:29 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Wolfram Sang, linux-i2c, Uwe Kleine-König

2016-04-14 16:24 GMT+08:00 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello Axel,
>
> On Thu, Apr 14, 2016 at 03:42:54PM +0800, Axel Lin 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.
>
> 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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: efm32: Prevent potential division by zero
  2016-04-14  8:29   ` Axel Lin
@ 2016-04-14  9:06     ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-04-14  9:06 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-i2c, Uwe Kleine-König, Wolfram Sang

Hello Axel,

On Thu, Apr 14, 2016 at 04:29:42PM +0800, Axel Lin wrote:
> 2016-04-14 16:24 GMT+08:00 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> > On Thu, Apr 14, 2016 at 03:42:54PM +0800, Axel Lin 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.
> >
> > 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 <u.kleine-koenig@pengutronix.de>

:-)

Best regards
Uwe

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-14  9:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-14  7:42 [PATCH] i2c: efm32: Prevent potential division by zero Axel Lin
2016-04-14  8:24 ` Uwe Kleine-König
2016-04-14  8:29   ` Axel Lin
2016-04-14  9:06     ` Uwe Kleine-König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.