linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] i2c: efm32: Prevent potential division by zero
@ 2016-04-14  9:49 Axel Lin
  2016-04-14 11:40 ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-14  9:49 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>
---
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(+)

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

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

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

Hello Axel,

On Thu, Apr 14, 2016 at 05:49:35PM +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.
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> 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

-- 
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 v2] i2c: efm32: Prevent potential division by zero
  2016-04-14 11:40 ` Uwe Kleine-König
@ 2016-04-14 14:17   ` Axel Lin
  2016-04-14 18:52     ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-14 14:17 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Wolfram Sang, linux-i2c, Uwe Kleine-König

2016-04-14 19:40 GMT+08:00 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello Axel,
>
> On Thu, Apr 14, 2016 at 05:49:35PM +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.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>> ---
>> 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.

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.

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

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

Hello Axel,

On Thu, Apr 14, 2016 at 10:17:45PM +0800, Axel Lin wrote:
> 2016-04-14 19:40 GMT+08:00 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> > On Thu, Apr 14, 2016 at 05:49:35PM +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.
> >>
> >> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> >> ---
> >> 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.
> 
> 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

-- 
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 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-14  9:49 [PATCH v2] i2c: efm32: Prevent potential division by zero Axel Lin
2016-04-14 11:40 ` Uwe Kleine-König
2016-04-14 14:17   ` Axel Lin
2016-04-14 18:52     ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).