[PATCH 3/3] i2c: brcmstb: Correct optional IRQ handling

[email protected]
Newsgroups gmane.linux.kernel,gmane.linux.drivers.i2c,gmane.linux.ports.arm.kernel
Message-ID <[email protected]>
From: bui duc phuc <[email protected]>

dev->irq is assigned from platform_get_irq_optional(), which returns a
non-zero interrupt number on success or a negative error number on
failure. Therefore, 0 is not a valid IRQ number.

Check for a positive IRQ number before requesting the IRQ instead of
treating 0 as a valid IRQ.

Also use a positive IRQ number when reporting the operating mode. The
driver sets dev->irq to -1 when devm_request_irq() fails, so the mode
check should only consider positive IRQ numbers as interrupt mode.

Signed-off-by: bui duc phuc <[email protected]>
---
 drivers/i2c/busses/i2c-brcmstb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-brcmstb.c b/drivers/i2c/busses/i2c-brcmstb.c
index 91525a36e575..3adc73f3d608 100644
--- a/drivers/i2c/busses/i2c-brcmstb.c
+++ b/drivers/i2c/busses/i2c-brcmstb.c
@@ -655,7 +655,7 @@ static int brcmstb_i2c_probe(struct platform_device *pdev)
 	brcmstb_i2c_enable_disable_irq(dev, INT_DISABLE);
 
 	/* register the ISR handler */
-	if (dev->irq >= 0) {
+	if (dev->irq > 0) {
 		rc = devm_request_irq(&pdev->dev, dev->irq, brcmstb_i2c_isr,
 				      IRQF_SHARED,
 				      int_name ? int_name : pdev->name,
@@ -697,7 +697,7 @@ static int brcmstb_i2c_probe(struct platform_device *pdev)
 
 	dev_info(dev->device, "%s@%dhz registered in %s mode\n",
 		 int_name ? int_name : " ", dev->clk_freq_hz,
-		 (dev->irq >= 0) ? "interrupt" : "polling");
+		 (dev->irq > 0) ? "interrupt" : "polling");
 
 	return 0;
 }
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.