[RFT,2/2] i2c: sun6i-p2wi: Prevent potential division by zero
diff mbox

Message ID 1460508870.6009.3.camel@ingics.com
State New
Headers show

Commit Message

Axel Lin April 13, 2016, 12:54 a.m. UTC
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(+)

Comments

Boris Brezillon April 13, 2016, 7:49 a.m. UTC | #1
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;

Patch
diff mbox

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;