linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT][PATCH 1/2] i2c: sirf: Prevent potential division by zero
@ 2016-04-13  0:49 Axel Lin
  2016-04-13  0:54 ` [RFT][PATCH 2/2] i2c: sun6i-p2wi: " Axel Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Axel Lin @ 2016-04-13  0:49 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Barry Song, Guoying Zhang, 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. Since the clock-frequency
property is optional in current code, use SIRFSOC_I2C_DEFAULT_SPEED
instead if clock-frequency is set to 0 in a DT.

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

diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index 792a42b..82743e4 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -353,7 +353,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
 
 	err = of_property_read_u32(pdev->dev.of_node,
 		"clock-frequency", &bitrate);
-	if (err < 0)
+	if (err < 0 || bitrate == 0)
 		bitrate = SIRFSOC_I2C_DEFAULT_SPEED;
 
 	/*
-- 
2.5.0

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

* [RFT][PATCH 2/2] i2c: sun6i-p2wi: Prevent potential division by zero
  2016-04-13  0:49 [RFT][PATCH 1/2] i2c: sirf: Prevent potential division by zero Axel Lin
@ 2016-04-13  0:54 ` Axel Lin
  2016-04-13  7:49   ` Boris Brezillon
  0 siblings, 1 reply; 3+ messages in thread
From: Axel Lin @ 2016-04-13  0:54 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Boris BREZILLON, Maxime Ripard, Chen-Yu Tsai, 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-sun6i-p2wi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c
index 7668e2e..6448291 100644
--- a/drivers/i2c/busses/i2c-sun6i-p2wi.c
+++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c
@@ -202,6 +202,11 @@ static int p2wi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	if (clk_freq == 0) {
+		dev_err(dev, "clock-frequency is set to 0 in DT\n");
+		return -EINVAL;
+	}
+
 	if (of_get_child_count(np) > 1) {
 		dev_err(dev, "P2WI only supports one slave device\n");
 		return -EINVAL;
-- 
2.5.0

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

* Re: [RFT][PATCH 2/2] i2c: sun6i-p2wi: Prevent potential division by zero
  2016-04-13  0:54 ` [RFT][PATCH 2/2] i2c: sun6i-p2wi: " Axel Lin
@ 2016-04-13  7:49   ` Boris Brezillon
  0 siblings, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2016-04-13  7:49 UTC (permalink / raw)
  To: Axel Lin; +Cc: Wolfram Sang, Maxime Ripard, Chen-Yu Tsai, linux-i2c

On Wed, 13 Apr 2016 08:54:30 +0800
Axel Lin <axel.lin@ingics.com> 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>

Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> ---
>  drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c
> index 7668e2e..6448291 100644
> --- a/drivers/i2c/busses/i2c-sun6i-p2wi.c
> +++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c
> @@ -202,6 +202,11 @@ static int p2wi_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> +	if (clk_freq == 0) {
> +		dev_err(dev, "clock-frequency is set to 0 in DT\n");
> +		return -EINVAL;
> +	}
> +
>  	if (of_get_child_count(np) > 1) {
>  		dev_err(dev, "P2WI only supports one slave device\n");
>  		return -EINVAL;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

end of thread, other threads:[~2016-04-13  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-13  0:49 [RFT][PATCH 1/2] i2c: sirf: Prevent potential division by zero Axel Lin
2016-04-13  0:54 ` [RFT][PATCH 2/2] i2c: sun6i-p2wi: " Axel Lin
2016-04-13  7:49   ` Boris Brezillon

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