Skip to contentSkip to conversation

Stop calling devm_request_irq() with invalid IRQs in the I2C bus drivers

PATCH Applied Sergey Shtylyov 3 participants 14 messages Apr 10, 2021 – Apr 17, 2021

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v2 cover Stop calling devm_request_irq() with invalid IRQs in the I2C bus drivers

Here are 6 patches against the 'master' branch of Martin Petersen's 'scsi.git' repo. The affected drivers call platform_get_irq() but largely ignore its result -- they blithely pass the negative error codes to devm_request_irq() which expects *unsinged* IRQ #s. Stop doing that by checking what exactly platform_get_irq() returns.

[1/6] i2c: cadence: add IRQ check
[2/6] i2c: emev2: add IRQ check
[3/6] i2c: jz4780: add IRQ check
[4/6] i2c: mlxbf: add IRQ check
[5/6] i2c: rcar: add IRQ check
[6/6] i2c: sh7760: add IRQ check

#1 lore raw

PATCH v2 1/6 i2c: cadence: add IRQ check

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes df8eb5691c48 ("i2c: Add driver for Cadence I2C controller")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-cadence.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-cadence.c +4 -1
Index: linux/drivers/i2c/busses/i2c-cadence.c
===================================================================
@@ -1200,7 +1200,10 @@ static int cdns_i2c_probe(struct platfor
 	if (IS_ERR(id->membase))
 		return PTR_ERR(id->membase);
 
-	id->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;
+	id->irq = ret;
 
 	id->adap.owner = THIS_MODULE;
 	id->adap.dev.of_node = pdev->dev.of_node;
#2 lore raw

PATCH v2 2/6 i2c: emev2: add IRQ check

In reply to Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes 5faf6e1f58b4 ("i2c: emev2: add driver")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-emev2.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-emev2.c +4 -1
Index: linux/drivers/i2c/busses/i2c-emev2.c
===================================================================
@@ -395,7 +395,10 @@ static int em_i2c_probe(struct platform_
 
 	em_i2c_reset(&priv->adap);
 
-	priv->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		goto err_clk;
+	priv->irq = ret;
 	ret = devm_request_irq(&pdev->dev, priv->irq, em_i2c_irq_handler, 0,
 				"em_i2c", priv);
 	if (ret)
#3 lore raw

PATCH v2 3/6 i2c: jz4780: add IRQ check

In reply to Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes ba92222ed63a ("i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-jz4780.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-jz4780.c +4 -1
Index: linux/drivers/i2c/busses/i2c-jz4780.c
===================================================================
@@ -825,7 +825,10 @@ static int jz4780_i2c_probe(struct platf
 
 	jz4780_i2c_writew(i2c, JZ4780_I2C_INTM, 0x0);
 
-	i2c->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		goto err;
+	i2c->irq = ret;
 	ret = devm_request_irq(&pdev->dev, i2c->irq, jz4780_i2c_irq, 0,
 			       dev_name(&pdev->dev), i2c);
 	if (ret)
#4 lore raw

PATCH v2 4/6 i2c: mlxbf: add IRQ check

In reply to Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes b5b5b32081cd ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-mlxbf.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-mlxbf.c +2 -0
Index: linux/drivers/i2c/busses/i2c-mlxbf.c
===================================================================
@@ -2376,6 +2376,8 @@ static int mlxbf_i2c_probe(struct platfo
 	mlxbf_i2c_init_slave(pdev, priv);
 
 	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
 	ret = devm_request_irq(dev, irq, mlxbf_smbus_irq,
 			       IRQF_ONESHOT | IRQF_SHARED | IRQF_PROBE_SHARED,
 			       dev_name(dev), priv);
#5 lore raw

PATCH v2 5/6 i2c: rcar: add IRQ check

In reply to Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with the invalid IRQ #s.

Fixes 6ccbe607132b ("i2c: add Renesas R-Car I2C driver")

---
Changes in version 2:
- avoided a string of assignements;
- added Geert's tag.

 drivers/i2c/busses/i2c-rcar.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-rcar.c +4 -1
Index: linux/drivers/i2c/busses/i2c-rcar.c
===================================================================
@@ -1027,7 +1027,10 @@ static int rcar_i2c_probe(struct platfor
 	if (of_property_read_bool(dev->of_node, "smbus"))
 		priv->flags |= ID_P_HOST_NOTIFY;
 
-	priv->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		goto out_pm_disable;
+	priv->irq = ret;
 	ret = devm_request_irq(dev, priv->irq, irqhandler, irqflags, dev_name(dev), priv);
 	if (ret < 0) {
 		dev_err(dev, "cannot get irq %d\n", priv->irq);
#6 lore raw

PATCH v2 6/6 i2c: sh7760: add IRQ check

In reply to Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes a26c20b1fa6d ("i2c: Renesas SH7760 I2C master driver")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-sh7760.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-sh7760.c +4 -1
Index: linux/drivers/i2c/busses/i2c-sh7760.c
===================================================================
@@ -471,7 +471,10 @@ static int sh7760_i2c_probe(struct platf
 		goto out2;
 	}
 
-	id->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;
+	id->irq = ret;
 
 	id->adap.nr = pdev->id;
 	id->adap.algo = &sh7760_i2c_algo;
#7 lore raw

Re: [PATCH v2 6/6] i2c: sh7760: add IRQ check

Quoted 21 lines · Sergey Shtylyov

The driver neglects to check the result of platform_get_irq()'s call and blithely passes the negative error codes to devm_request_irq() (which takes *unsigned* IRQ #), causing it to fail with -EINVAL, overriding an original error code. Stop calling devm_request_irq() with invalid IRQ #s.

Fixes a26c20b1fa6d ("i2c: Renesas SH7760 I2C master driver")

---
Changes in version 2:
- new patch.

 drivers/i2c/busses/i2c-sh7760.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Index: linux/drivers/i2c/busses/i2c-sh7760.c
===================================================================

drivers/i2c/busses/i2c-sh7760.c static int sh7760_i2c_probe(struct platf · line 476

Quoted 7 lines
drivers/i2c/busses/i2c-sh7760.c +3 -1
@@ -471,7 +471,10 @@ static int sh7760_i2c_probe(struct platf
 		goto out2;
 	}
 
-	id->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;

Should have been *goto* out3. Sorry for my overlook! :-/

[...]

MBR, Sergey

#8 lore raw

Re: [PATCH v2 6/6] i2c: sh7760: add IRQ check

Quoted 7 lines

drivers/i2c/busses/i2c-sh7760.c static int sh7760_i2c_probe(struct platf · line 476

Quoted 5 lines
drivers/i2c/busses/i2c-sh7760.c +3 -1
-	id->irq = platform_get_irq(pdev, 0);
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;

Should have been *goto* out3. Sorry for my overlook! :-/

Please send an incremental patch. Thanks!

#9 lore raw
In reply to Sergey Shtylyov
Quoted 10 lines · Sergey Shtylyov

Here are 6 patches against the 'master' branch of Martin Petersen's 'scsi.git' repo. The affected drivers call platform_get_irq() but largely ignore its result -- they blithely pass the negative error codes to devm_request_irq() which expects *unsinged* IRQ #s. Stop doing that by checking what exactly platform_get_irq() returns.

[1/6] i2c: cadence: add IRQ check
[2/6] i2c: emev2: add IRQ check
[3/6] i2c: jz4780: add IRQ check
[4/6] i2c: mlxbf: add IRQ check
[5/6] i2c: rcar: add IRQ check

Forgot to mention that the whole v2 patch set grew from this R-Car patch.

Quoted 1 line

[6/6] i2c: sh7760: add IRQ check

MBR, Sergey

#10 lore raw
In reply to Sergey Shtylyov
Quoted 1 line · Sergey Shtylyov

Here are 6 patches against the 'master' branch of Martin Petersen's 'scsi.git' repo.

Oops, left that line unfinished. Wolfram's 'linux.git' repo, of course... :-)

Quoted 3 lines

The affected drivers call platform_get_irq() but largely ignore its result -- they blithely pass the negative error codes to devm_request_irq() which expects *unsinged* IRQ #s. Stop doing that by checking what exactly platform_get_irq() returns.

[...]

MNR, Sergey

maintainer Applied
#11 lore raw
In reply to Sergey Shtylyov
Quoted 11 lines · Sergey Shtylyov

Here are 6 patches against the 'master' branch of Martin Petersen's 'scsi.git' repo. The affected drivers call platform_get_irq() but largely ignore its result -- they blithely pass the negative error codes to devm_request_irq() which expects *unsinged* IRQ #s. Stop doing that by checking what exactly platform_get_irq() returns.

[1/6] i2c: cadence: add IRQ check
[2/6] i2c: emev2: add IRQ check
[3/6] i2c: jz4780: add IRQ check
[4/6] i2c: mlxbf: add IRQ check
[5/6] i2c: rcar: add IRQ check
[6/6] i2c: sh7760: add IRQ check

Applied to for-next, thanks!

#12 lore raw

PATCH 1/1 i2c: sh7760: fix IRQ error path

In reply to Sergey Shtylyov

While adding the invalid IRQ check after calling platform_get_irq(), I managed to overlook that the driver has a complex error path in its probe() method, thus a simple *return* couldn't be used. Use a proper *goto* instead!

Fixes e5b2e3e74201 ("i2c: sh7760: add IRQ check")

---
This patch is against the '2c/for-next' branch of Wolfram's 'linux.git' repo. I wasn't even able to complie-test it though...

 drivers/i2c/busses/i2c-sh7760.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-sh7760.c +1 -1
Index: linux/drivers/i2c/busses/i2c-sh7760.c
===================================================================
@@ -473,7 +473,7 @@ static int sh7760_i2c_probe(struct platf
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
-		return ret;
+		goto out3;
 	id->irq = ret;
 
 	id->adap.nr = pdev->id;
Applied
#13 lore raw

Re: [PATCH] i2c: sh7760: fix IRQ error path

Quoted 8 lines · Sergey Shtylyov

While adding the invalid IRQ check after calling platform_get_irq(), I managed to overlook that the driver has a complex error path in its probe() method, thus a simple *return* couldn't be used. Use a proper *goto* instead!

Fixes e5b2e3e74201 ("i2c: sh7760: add IRQ check")

Applied to for-next, thanks!