Skip to contentSkip to conversation

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

PATCH Applied Sergey Shtylyov 3 participants 5 messages Mar 25, 2021 – Mar 26, 2021

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

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

Here are 2 patches against the 'master' branch of the Jens Axboe's 'linux-block.git' repo. The affected drivers call platform_get_irq() but mis-interprete its result -- they consider IRQ0 as error and the real error codes as valid IRQs... :-/

[1/2] pata_arasan_cf: fix IRQ check
[2/2] pata_ipx4xx_cf: fix IRQ check

#1 lore raw

PATCH 1/2 pata_arasan_cf: fix IRQ check

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 ata_host_activate(), propagate upstream -EPROBE_DEFER, and set up the driver to polling mode on (negative) errors and IRQ0 (libata treats IRQ #0 as a polling mode anyway)...

Fixes a480167b23ef ("pata_arasan_cf: Adding support for arasan compact flash host controller")

---
This patch is against the 'master' branch of Jens Axboe's 'linux-block.git' repo.

 drivers/ata/pata_arasan_cf.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/ata/pata_arasan_cf.c +11 -4
Index: linux-block/drivers/ata/pata_arasan_cf.c
===================================================================
@@ -818,12 +818,19 @@ static int arasan_cf_probe(struct platfo
 	else
 		quirk = CF_BROKEN_UDMA; /* as it is on spear1340 */
 
-	/* if irq is 0, support only PIO */
-	acdev->irq = platform_get_irq(pdev, 0);
-	if (acdev->irq)
+	/*
+	 * If there's an error getting IRQ (or we do get IRQ0),
+	 * support only PIO
+	 */
+	ret = platform_get_irq(pdev, 0);
+	if (ret > 0) {
+		acdev->irq = ret;
 		irq_handler = arasan_cf_interrupt;
-	else
+	} else	if (ret == -EPROBE_DEFER) {
+		return ret;
+	} else	{
 		quirk |= CF_BROKEN_MWDMA | CF_BROKEN_UDMA;
+	}
 
 	acdev->pbase = res->start;
 	acdev->vbase = devm_ioremap(&pdev->dev, res->start,
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] pata_arasan_cf: fix IRQ check

Quoted 35 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 ata_host_activate(), propagate upstream -EPROBE_DEFER, and set up the driver to polling mode on (negative) errors and IRQ0 (libata treats IRQ #0 as a polling mode anyway)...

Fixes a480167b23ef ("pata_arasan_cf: Adding support for arasan compact flash host controller")

---
This patch is against the 'master' branch of Jens Axboe's 'linux-block.git' repo.

 drivers/ata/pata_arasan_cf.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-block/drivers/ata/pata_arasan_cf.c
===================================================================

drivers/ata/pata_arasan_cf.c +7 -3
@@ -818,12 +818,19 @@ static int arasan_cf_probe(struct platfo
 	else
 		quirk = CF_BROKEN_UDMA; /* as it is on spear1340 */
 
-	/* if irq is 0, support only PIO */
-	acdev->irq = platform_get_irq(pdev, 0);
-	if (acdev->irq)
+	/*
+	 * If there's an error getting IRQ (or we do get IRQ0),
+	 * support only PIO
+	 */
+	ret = platform_get_irq(pdev, 0);
+	if (ret > 0) {
+		acdev->irq = ret;

drivers/ata/pata_arasan_cf.c static int arasan_cf_probe(struct platfo · line 836

Quoted 10 lines
drivers/ata/pata_arasan_cf.c +4 -1
 		irq_handler = arasan_cf_interrupt;
-	else
+	} else	if (ret == -EPROBE_DEFER) {
+		return ret;
+	} else	{
 		quirk |= CF_BROKEN_MWDMA | CF_BROKEN_UDMA;
+	}
 
 	acdev->pbase = res->start;
 	acdev->vbase = devm_ioremap(&pdev->dev, res->start,
Signature · 1 line
viresh
#3 lore raw

PATCH 2/2 pata_ipx4xx_cf: 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 ata_host_activate(), propagate errors upstream, and treat IRQ0 as error, returning -EINVAL, as the libata code treats 0 as an indication that polling should be used anyway...

Fixes 0df0d0a0ea9f ("[libata] ARM: add ixp4xx PATA driver")
---
 drivers/ata/pata_ixp4xx_cf.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/ata/pata_ixp4xx_cf.c +5 -1
Index: linux-block/drivers/ata/pata_ixp4xx_cf.c
===================================================================
@@ -165,8 +165,12 @@ static int ixp4xx_pata_probe(struct plat
 		return -ENOMEM;
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq)
+	if (irq > 0)
 		irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
+	else if (irq < 0)
+		return irq;
+	else
+		return -EINVAL;
 
 	/* Setup expansion bus chip selects */
 	*data->cs0_cfg = data->cs0_bits;
Applied
#4 lore raw
In reply to Sergey Shtylyov
Quoted 6 lines · Sergey Shtylyov

Here are 2 patches against the 'master' branch of the Jens Axboe's 'linux-block.git' repo. The affected drivers call platform_get_irq() but mis-interprete its result -- they consider IRQ0 as error and the real error codes as valid IRQs... :-/

[1/2] pata_arasan_cf: fix IRQ check
[2/2] pata_ipx4xx_cf: fix IRQ check

Applied, thanks.

Signature · 1 line
Jens Axboe