diff mbox series

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

Message ID fd0dd13c-2fe7-c954-ff0f-917067c8252c@omp.ru
State Not Applicable
Headers show
Series Correctly handle plaform_get_irq()'s result in the i2C drivers | expand

Commit Message

Sergey Shtylyov July 4, 2021, 2:41 p.m. UTC
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")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
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(-)

Comments

Wolfram Sang Aug. 17, 2021, 8:08 p.m. UTC | #1
On Sun, Jul 04, 2021 at 05:41:50PM +0300, Sergey Shtylyov wrote:
> 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")
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

The driver has been removed meanwhile.
diff mbox series

Patch

Index: linux/drivers/i2c/busses/i2c-pmcmsp.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-pmcmsp.c
+++ 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);