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

Sergey Shtylyov
2021-07-04T14:41:58Z

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

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