ata: pata_mpc52xx: convert to platform_get_irq()
PATCH 1/1 ata: pata_mpc52xx: convert to platform_get_irq()
Replace irq_of_parse_and_map() with platform_get_irq(), which returns a negative errno on failure and integrates with the platform device model. Since platform_get_irq() does not create a separately managed mapping, the corresponding irq_dispose_mapping() calls in the probe error path and remove function are no longer needed.
--- drivers/ata/pata_mpc52xx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/ata/pata_mpc52xx.c +3 -5
@@ -730,10 +730,10 @@ static int mpc52xx_ata_probe(struct platform_device *op)if ((prop) && (proplen >=4 )) udma_mask =ATA_UDMA2 & ((1 << (*prop +1 )) -1 ); - ata_irq =irq_of_parse_and_map (op->dev.of_node,0 ); -if (!ata_irq) { + ata_irq =platform_get_irq (op,0 ); +if (ata_irq <0 ) {dev_err (&op->dev,"error mapping irq\n" ); -return -EINVAL ; +return ata_irq; }/* Prepare our private structure */
@@ -796,7 +796,6 @@ static int mpc52xx_ata_probe(struct platform_device *op)irq_dispose_mapping (task_irq);bcom_ata_release (dmatsk); err1: -irq_dispose_mapping (ata_irq);return rv; }
@@ -813,7 +812,6 @@ static void mpc52xx_ata_remove(struct platform_device *op) task_irq =bcom_get_task_irq (priv->dmatsk);irq_dispose_mapping (task_irq);bcom_ata_release (priv->dmatsk); -irq_dispose_mapping (priv->ata_irq); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Redundant error logging after platform_get_irq() breaks probe deferral silence.
Pre-existing issues:
- [High] Teardown inversion and double-free vulnerabilities due to manual cleanup of resources before devm-managed IRQ handler deregistration. --
commit ffac71fcd5afc61a5b03a064fe40da6b52105e95
Author: Rosen Penev <[email protected]>
ata: pata_mpc52xx: convert to platform_get_irq()
Replace irq_of_parse_and_map() with platform_get_irq(), which returns a negative errno on failure and integrates with the platform device model. The corresponding irq_dispose_mapping() calls in the probe error path and remove function are no longer needed.
Quoted 4 lines
drivers/ata/pata_mpc52xx.c +0
-0
[ ... ]
drivers/ata/pata_mpc52xx.c static int mpc52xx_ata_probe(struct platform_device *op) · line 735
Quoted 9 lines
drivers/ata/pata_mpc52xx.c +2
-2@@ -730,10 +730,10 @@ static int mpc52xx_ata_probe(struct platform_device *op)if ((prop) && (proplen >=4 )) udma_mask =ATA_UDMA2 & ((1 << (*prop +1 )) -1 ); - ata_irq =irq_of_parse_and_map (op->dev.of_node,0 ); -if (!ata_irq) { + ata_irq =platform_get_irq (op,0 ); +if (ata_irq <0 ) {dev_err (&op->dev,"error mapping irq\n" );
[Severity: Medium]
Since platform_get_irq() already logs errors internally using dev_err_probe(), which correctly silences -EPROBE_DEFER, does leaving this manual dev_err() call in place cause redundant log spam during probe deferral?
Quoted 5 lines
drivers/ata/pata_mpc52xx.c +1
-1-return -EINVAL ; +return ata_irq; }/* Prepare our private structure */
[ ... ]
drivers/ata/pata_mpc52xx.c static int mpc52xx_ata_probe(struct platform_device *op) · line 797
Quoted 3 lines
drivers/ata/pata_mpc52xx.c +0
-0@@ -796,7 +796,6 @@ static int mpc52xx_ata_probe(struct platform_device *op)irq_dispose_mapping (task_irq);bcom_ata_release (dmatsk);
[Severity: High]
This is a pre-existing issue, but does manually cleaning up the resources here cause a use-after-free and teardown inversion?
Because the driver requests task_irq using devm_request_irq(), the interrupt handler remains active until devres frees it after the probe error path returns.
If bcom_ata_release(dmatsk) frees the memory while the devm-managed IRQ handler is still registered, could an incoming interrupt access freed memory?
Additionally, disposing the IRQ mapping while the interrupt action is still registered breaks the IRQ subsystem, as devm_free_irq() will later fail to locate the descriptor.
Finally, since bcom_ata_release() internally calls bcom_task_free(), which also calls irq_dispose_mapping(tsk->irq), does this sequence trigger a double-free of the IRQ mapping?
drivers/ata/pata_mpc52xx.c static void mpc52xx_ata_remove(struct platform_device *op) · line 814
Quoted 9 lines
drivers/ata/pata_mpc52xx.c +0
-1err1: -irq_dispose_mapping (ata_irq);return rv; }@@ -813,7 +812,6 @@ static void mpc52xx_ata_remove(struct platform_device *op) task_irq =bcom_get_task_irq (priv->dmatsk);irq_dispose_mapping (task_irq);bcom_ata_release (priv->dmatsk);
[Severity: High]
This is a pre-existing issue, but does this pattern present the same use-after-free, teardown inversion, and double-free risks as the probe error path?
Since the IRQ handler is managed by devm, it is still active when this remove function returns. Manually releasing the task resources and IRQ mapping before devres unregisters the handler seems problematic.
Quoted 4 lines
drivers/ata/pata_mpc52xx.c +0
-1-irq_dispose_mapping (priv->ata_irq); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 17 lines · Rosen Penev
Replace
irq_of_parse_and_map()withplatform_get_irq(), which returns a negative errno on failure and integrates with the platform device model. Sinceplatform_get_irq()does not create a separately managed mapping, the correspondingirq_dispose_mapping()calls in the probe error path and remove function are no longer needed.Assisted-by opencode:big-pickleSigned-off-by Rosen Penev <[email protected]>--- drivers/ata/pata_mpc52xx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/ata/pata_mpc52xx.c +0
-0
drivers/ata/pata_mpc52xx.c static int mpc52xx_ata_probe(struct platform_device *op) · line 735
Quoted 8 lines
drivers/ata/pata_mpc52xx.c +2
-2@@ -730,10 +730,10 @@ static int mpc52xx_ata_probe(struct platform_device *op)if ((prop) && (proplen >=4 )) udma_mask =ATA_UDMA2 & ((1 << (*prop +1 )) -1 ); - ata_irq =irq_of_parse_and_map (op->dev.of_node,0 ); -if (!ata_irq) { + ata_irq =platform_get_irq (op,0 ); +if (ata_irq <0 ) {dev_err (&op->dev,"error mapping irq\n" );
s/mapping/getting/?
But actually platform_get_irq() loudly curses on error already... :-)
[...]
MBR, Sergey