i2c: sirf: Prevent potential division by zero
Subsystems (2)
PATCH 1/2 i2c: sirf: Prevent potential division by zero
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 <[email protected]>
--- drivers/i2c/busses/i2c-sirf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-sirf.c +1 -1
@@ -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 ;/*
Signature · 1 line
2.5.0
PATCH 2/2 i2c: sun6i-p2wi: Prevent potential division by zero
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 <[email protected]>
--- drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/i2c/busses/i2c-sun6i-p2wi.c +5 -0
@@ -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 ;
Signature · 1 line
2.5.0
Re: [RFT][PATCH 2/2] i2c: sun6i-p2wi: Prevent potential division by zero
Quoted 4 lines · On Wed, 13 Apr 2016 08:54:30 +0800 Axel Lin <[email protected]> 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 <[email protected]>
Acked-by Boris Brezillon <[email protected]>
Quoted 20 lines
--- drivers/i2c/busses/i2c-sun6i-p2wi.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/i2c/busses/i2c-sun6i-p2wi.c +5
-0@@ -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 ;
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com