Skip to contentSkip to conversation

Correctly handle plaform_get_irq()'s result in the i2C drivers

PATCH Applied Sergey Shtylyov 4 participants 17 messages Jul 4, 2021 – Aug 25, 2021

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

v2 cover Correctly handle plaform_get_irq()'s result in the i2C drivers

Here are 5 patches against the 'i2c/for-current' branch of Wolfram's 'linux.git' repo. The affected drivers call platform_get_irq() but mis-interprete its result -- they consider IRQ0 as error and (sometimes) the real error codes as valid IRQs... :-/

[1/5] i2c: hix5hd2: fix IRQ check
[2/5] i2c: mt65xx: fix IRQ check
[3/5] i2c: pmcmsp: fix IRQ check
[4/5] i2c: s3c2410: fix IRQ check
[5/5] i2c: xlp9xx: fix main IRQ check

#1 lore raw

PATCH v2 1/5 i2c: hix5hd2: fix IRQ check

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 15ef27756b23 ("i2c: hix5hd2: add i2c controller driver")
---
 drivers/i2c/busses/i2c-hix5hd2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-hix5hd2.c +1 -1
Index: linux/drivers/i2c/busses/i2c-hix5hd2.c
===================================================================
@@ -413,7 +413,7 @@ static int hix5hd2_i2c_probe(struct plat
 		return PTR_ERR(priv->regs);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	priv->clk = devm_clk_get(&pdev->dev, NULL);
Applied
#2 lore raw

Re: [PATCH v2 1/5] i2c: hix5hd2: fix IRQ check

Quoted 7 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 15ef27756b23 ("i2c: hix5hd2: add i2c controller driver")

Applied to for-next, thanks!

#3 lore raw

PATCH v2 2/5 i2c: mt65xx: fix IRQ check

In reply to Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes ce38815d39ea ("I2C: mediatek: Add driver for MediaTek I2C controller")
---
 drivers/i2c/busses/i2c-mt65xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mt65xx.c +1 -1
Index: linux/drivers/i2c/busses/i2c-mt65xx.c
===================================================================
@@ -1211,7 +1211,7 @@ static int mtk_i2c_probe(struct platform
 		return PTR_ERR(i2c->pdmabase);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	init_completion(&i2c->msg_complete);
#4 lore raw

Re: [PATCH v2 2/5] i2c: mt65xx: fix IRQ check

Quoted 6 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes ce38815d39ea ("I2C: mediatek: Add driver for MediaTek I2C controller")

Qii Wang, do you like this patch?

Quoted 18 lines
---
 drivers/i2c/busses/i2c-mt65xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/i2c/busses/i2c-mt65xx.c +1 -1
@@ -1211,7 +1211,7 @@ static int mtk_i2c_probe(struct platform
 		return PTR_ERR(i2c->pdmabase);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	init_completion(&i2c->msg_complete);
maintainer Reviewed-by
#5 lore raw

Re: [PATCH v2 2/5] i2c: mt65xx: fix IRQ check

Quoted 10 lines · Wolfram Sang
Quoted 6 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes ce38815d39ea ("I2C: mediatek: Add driver for MediaTek I2C controller")

Qii Wang, do you like this patch?

It is ok.

Thanks

Quoted 18 lines
Quoted 18 lines
---
 drivers/i2c/busses/i2c-mt65xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/i2c/busses/i2c-mt65xx.c +1 -1
@@ -1211,7 +1211,7 @@ static int mtk_i2c_probe(struct platform
 		return PTR_ERR(i2c->pdmabase);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	init_completion(&i2c->msg_complete);
Applied
#6 lore raw

Re: [PATCH v2 2/5] i2c: mt65xx: fix IRQ check

In reply to Sergey Shtylyov
Quoted 7 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes ce38815d39ea ("I2C: mediatek: Add driver for MediaTek I2C controller")

Applied to for-next, thanks!

#7 lore raw

PATCH v2 3/5 i2c: pmcmsp: fix IRQ check

In reply to Sergey Shtylyov

The driver's probe() method is written as if platform_get_irq() returns 0 on error, while actually it returns a negative error code (with all the other values considered valid IRQs). Rewrite the driver's IRQ checking code to pass the positive IRQ #s to request_irq() and use polling mode when platform_get_irq() returns negative error code (or IRQ0)...

Fixes 1b144df1d7d6 ("i2c: New PMC MSP71xx TWI bus driver")

---
Changes in version 2:
- fixed the IRQ validity check, assigning the result of platform_get_irq() call to the 'rc' variable first;
- merging the code enforcing the polling mode on bad IRQ in one place (after calling request_irq() and handling its result);
- removed explicit check for the deferred probe, fixed up the patch description accordingly;
- removed the dashes in the patch subject;
- refreshed the patch.

drivers/i2c/busses/i2c-pmcmsp.c | 8 +++++---

 drivers/i2c/busses/i2c-pmcmsp.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-pmcmsp.c +9 -3
Index: linux/drivers/i2c/busses/i2c-pmcmsp.c
===================================================================
@@ -291,8 +291,9 @@ static int pmcmsptwi_probe(struct platfo
 	}
 
 	/* request the irq */
-	pmcmsptwi_data.irq = platform_get_irq(pldev, 0);
-	if (pmcmsptwi_data.irq) {
+	rc = platform_get_irq(pldev, 0);
+	pmcmsptwi_data.irq = rc;
+	if (rc > 0) {
 		rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt,
 				 IRQF_SHARED, pldev->name, &pmcmsptwi_data);
 		if (rc == 0) {
@@ -312,9 +313,14 @@ static int pmcmsptwi_probe(struct platfo
 				"Could not assign TWI IRQ handler "
 				"to irq %d (continuing with poll)\n",
 				pmcmsptwi_data.irq);
-			pmcmsptwi_data.irq = 0;
 		}
 	}
+	/*
+	 * We only get here with a negative rc if either platform_get_irq() or
+	 * request_irq() call has failed; we have to enforce the polling mode...
+	 */
+	if (rc < 0)
+		pmcmsptwi_data.irq = 0;
 
 	init_completion(&pmcmsptwi_data.wait);
 	mutex_init(&pmcmsptwi_data.lock);
#8 lore raw

Re: [PATCH v2 3/5] i2c: pmcmsp: fix IRQ check

Quoted 8 lines · Sergey Shtylyov

The driver's probe() method is written as if platform_get_irq() returns 0 on error, while actually it returns a negative error code (with all the other values considered valid IRQs). Rewrite the driver's IRQ checking code to pass the positive IRQ #s to request_irq() and use polling mode when platform_get_irq() returns negative error code (or IRQ0)...

Fixes 1b144df1d7d6 ("i2c: New PMC MSP71xx TWI bus driver")

The driver has been removed meanwhile.

#9 lore raw

PATCH v2 4/5 i2c: s3c2410: fix IRQ check

In reply to Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c-s3c2410: Change IRQ to be plain integer.")
---
 drivers/i2c/busses/i2c-s3c2410.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-s3c2410.c +1 -1
Index: linux/drivers/i2c/busses/i2c-s3c2410.c
===================================================================
@@ -1137,7 +1137,7 @@ static int s3c24xx_i2c_probe(struct plat
 	 */
 	if (!(i2c->quirks & QUIRK_POLL)) {
 		i2c->irq = ret = platform_get_irq(pdev, 0);
-		if (ret <= 0) {
+		if (ret < 0) {
 			dev_err(&pdev->dev, "cannot find IRQ\n");
 			clk_unprepare(i2c->clk);
 			return ret;
Reviewed-by on v2 4/5
#10 lore raw

Re: [PATCH v2 4/5] i2c: s3c2410: fix IRQ check

Quoted 10 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c-s3c2410: Change IRQ to be plain integer.")
---
 drivers/i2c/busses/i2c-s3c2410.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Best regards,
Krzysztof

Applied
#11 lore raw

Re: [PATCH v2 4/5] i2c: s3c2410: fix IRQ check

In reply to Sergey Shtylyov
Quoted 7 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c-s3c2410: Change IRQ to be plain integer.")

Applied to for-next, thanks!

#12 lore raw

PATCH v2 5/5 i2c: xlp9xx: fix main IRQ check

In reply to Sergey Shtylyov

Iff platform_get_irq() returns 0 for the main IRQ, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller")
---
 drivers/i2c/busses/i2c-xlp9xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-xlp9xx.c +1 -1
Index: linux/drivers/i2c/busses/i2c-xlp9xx.c
===================================================================
@@ -517,7 +517,7 @@ static int xlp9xx_i2c_probe(struct platf
 		return PTR_ERR(priv->base);
 
 	priv->irq = platform_get_irq(pdev, 0);
-	if (priv->irq <= 0)
+	if (priv->irq < 0)
 		return priv->irq;
 	/* SMBAlert irq */
 	priv->alert_data.irq = platform_get_irq(pdev, 1);
#13 lore raw

Re: [PATCH v2 5/5] i2c: xlp9xx: fix main IRQ check

Quoted 8 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0 for the main IRQ, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller")

George, do you like this patch?

Quoted 17 lines
---
 drivers/i2c/busses/i2c-xlp9xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

drivers/i2c/busses/i2c-xlp9xx.c +1 -1
@@ -517,7 +517,7 @@ static int xlp9xx_i2c_probe(struct platf
 		return PTR_ERR(priv->base);
 
 	priv->irq = platform_get_irq(pdev, 0);
-	if (priv->irq <= 0)
+	if (priv->irq < 0)
 		return priv->irq;
 	/* SMBAlert irq */
 	priv->alert_data.irq = platform_get_irq(pdev, 1);
Applied
#14 lore raw

Re: [PATCH v2 5/5] i2c: xlp9xx: fix main IRQ check

In reply to Sergey Shtylyov
Quoted 8 lines · Sergey Shtylyov

Iff platform_get_irq() returns 0 for the main IRQ, the driver's probe() method will return 0 early (as if the method's call was successful). Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always override that decision...

Fixes 2bbd681ba2b ("i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller")

Applied to for-next, thanks!

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

Here are 5 patches against the 'i2c/for-current' branch of Wolfram's 'linux.git' repo. The affected drivers call platform_get_irq() but mis-interprete its result -- they consider IRQ0 as error and (sometimes) the real error codes as valid IRQs... :-/

[1/5] i2c: hix5hd2: fix IRQ check
[2/5] i2c: mt65xx: fix IRQ check
[3/5] i2c: pmcmsp: fix IRQ check
[4/5] i2c: s3c2410: fix IRQ check
[5/5] i2c: xlp9xx: fix main IRQ check

Wolfram, hat's up with this series (its status in the patchwork is still "new")?

MBR, Sergey

#16 lore raw
Quoted 11 lines · Sergey Shtylyov
Quoted 9 lines

Here are 5 patches against the 'i2c/for-current' branch of Wolfram's 'linux.git' repo. The affected drivers call platform_get_irq() but mis-interprete its result -- they consider IRQ0 as error and (sometimes) the real error codes as valid IRQs... :-/

[1/5] i2c: hix5hd2: fix IRQ check
[2/5] i2c: mt65xx: fix IRQ check
[3/5] i2c: pmcmsp: fix IRQ check
[4/5] i2c: s3c2410: fix IRQ check
[5/5] i2c: xlp9xx: fix main IRQ check

Wolfram, hat's up with this series (its status in the patchwork is still "new")?

What's, of/c. :-)

MBR, Sergey