Handle optional IRQs correctly
Subsystems (3)
cover Handle optional IRQs correctly
From: bui duc phuc <[email protected]>
Hi all,
The changes were found through code inspection while reviewing optional IRQ handling in I2C drivers.
I noticed that some drivers already handle the return value of platform_get_irq_optional() explicitly, including i2c-designware-platdrv, i2c-ocores, and i2c-sh_mobile.
This series updates the affected drivers to properly handle errors from platform_get_irq_optional() and distinguish a missing optional IRQ from other errors.
The series also fixes the handling of IRQ 0 in the brcmstb driver, since 0 is not a valid IRQ number returned by platform_get_irq_optional().
The series was only compile-tested.
Best regards,
Phuc
bui duc phuc (3):
i2c: pca-platform: Handle errors from optional IRQ lookup
i2c: brcmstb: Handle errors from optional IRQ lookup
i2c: brcmstb: Correct optional IRQ handling
drivers/i2c/busses/i2c-brcmstb.c | 6 ++++-- drivers/i2c/busses/i2c-pca-platform.c | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 i2c: pca-platform: Handle errors from optional IRQ lookup
From: bui duc phuc <[email protected]>
platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.
Propagate negative errors other than -ENXIO.
--- drivers/i2c/busses/i2c-pca-platform.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-pca-platform.c +4 -1
@@ -139,8 +139,11 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) irq =platform_get_irq_optional (pdev,0 );/* If irq is 0, we do polling. */ -if (irq <0 ) +if (irq <0 ) { +if (irq != -ENXIO ) +return irq; irq =0 ; + } i2c =devm_kzalloc (&pdev->dev,sizeof (*i2c),GFP_KERNEL );if (!i2c)
Signature · 1 line
2.43.0
PATCH 2/3 i2c: brcmstb: Handle errors from optional IRQ lookup
In reply to [email protected]From: bui duc phuc <[email protected]>
platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.
Propagate negative errors other than -ENXIO.
--- drivers/i2c/busses/i2c-brcmstb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-brcmstb.c +2 -0
@@ -648,6 +648,8 @@ static int brcmstb_i2c_probe(struct platform_device *pdev)/* Get the interrupt number */ dev->irq =platform_get_irq_optional (pdev,0 ); +if (dev->irq <0 && dev->irq != -ENXIO ) +return dev->irq;/* disable the bsc interrupt line */ brcmstb_i2c_enable_disable_irq (dev,INT_DISABLE );
Signature · 1 line
2.43.0
PATCH 3/3 i2c: brcmstb: Correct optional IRQ handling
In reply to [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.
--- drivers/i2c/busses/i2c-brcmstb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-brcmstb.c +2 -2
@@ -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 ; }
Signature · 1 line
2.43.0