Skip to content

Commit

Permalink
i2c: sun6i-p2wi: Prevent potential division by zero
Browse files Browse the repository at this point in the history
[ Upstream commit 5ac61d2 ]

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>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
AxelLin authored and gregkh committed Nov 28, 2023
1 parent 0b5e729 commit 32b17bc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/i2c/busses/i2c-sun6i-p2wi.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,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;
Expand Down

0 comments on commit 32b17bc

Please sign in to comment.