dmaengine: fsldma: convert to platform_get_irq_optional()
Subsystems (2)
PATCH v3 1/1 dmaengine: fsldma: convert to platform_get_irq_optional()
Replace the per-controller irq_of_parse_and_map() call with platform_get_irq_optional(). The controller IRQ is optional when absent and the driver falls back to per-channel IRQs. The corresponding irq_dispose_mapping() calls in the probe error path and remove function are removed.
Moved before anything else in order to handle -EPROBE_DEFER and to avoid doing extra work. Simplifies the if statements as well.
---
v3: fix build error from the move
v2: move to the front of probe.
drivers/dma/fsldma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/dma/fsldma.c +8 -3
@@ -1224,8 +1224,13 @@ static int fsldma_of_probe(struct platform_device *op)struct fsldma_device *fdev;struct device_node *child;unsigned int i; +int irq;int err; + irq =platform_get_irq_optional (op,0 ); +if (irq == -EPROBE_DEFER ) +return irq; + fdev =kzalloc_obj (*fdev);if (!fdev) { err = -ENOMEM ;
@@ -1246,7 +1251,9 @@ static int fsldma_of_probe(struct platform_device *op) }/* map the channel IRQ if it exists, but don't hookup the handler yet */ - fdev->irq =irq_of_parse_and_map (op->dev.of_node,0 ); + fdev->irq = irq; +if (fdev->irq <0 ) + fdev->irq =0 ;dma_cap_set (DMA_MEMCPY , fdev->common.cap_mask);dma_cap_set (DMA_SLAVE , fdev->common.cap_mask);
@@ -1308,7 +1315,6 @@ static int fsldma_of_probe(struct platform_device *op)if (fdev->chan[i])fsl_dma_chan_remove (fdev->chan[i]); } -irq_dispose_mapping (fdev->irq);iounmap (fdev->regs); out_free:kfree (fdev);
@@ -1330,7 +1336,6 @@ static void fsldma_of_remove(struct platform_device *op)if (fdev->chan[i])fsl_dma_chan_remove (fdev->chan[i]); } -irq_dispose_mapping (fdev->irq);iounmap (fdev->regs);kfree (fdev);
Signature · 1 line
2.55.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:
Pre-existing issues:
- [High] The return value of dma_async_device_register() is completely ignored, leading to silent failures and a potential zombie driver state that corrupts core DMA IDA state on removal.
- [High] Missing tasklet_kill() before freeing the DMA channel structure leads to a potential Use-After-Free if a tasklet is scheduled during teardown.
--
commit d7e04e63631501d249cff16deb847b2b702a2b37
Author: Rosen Penev <[email protected]>
dmaengine: fsldma: convert to platform_get_irq_optional()
Replace the per-controller irq_of_parse_and_map() call with platform_get_irq_optional(). The controller IRQ is optional when absent and the driver falls back to per-channel IRQs.
Quoted 4 lines
drivers/dma/fsldma.c +0
-0
[ ... ]
drivers/dma/fsldma.c static int fsldma_of_probe(struct platform_device *op) · line 1308
Quoted 3 lines
drivers/dma/fsldma.c +0
-0@@ -1300,7 +1307,6 @@ static int fsldma_of_probe(struct platform_device *op)if (fdev->chan[i])fsl_dma_chan_remove (fdev->chan[i]);
[Severity: High]
This is a pre-existing issue, but does fsl_dma_chan_remove() fail to explicitly kill the tasklet before freeing the channel structure?
During device removal or probe error paths, fsldma_free_irqs() calls free_irq(). If a hardware interrupt executes just before free_irq(), it schedules chan->tasklet. free_irq() waits for the hardirq handler to finish but does not wait for pending softirqs.
The driver then calls fsl_dma_chan_remove() which invokes kfree(chan) without calling tasklet_kill(&chan->tasklet).
When the softirq scheduler subsequently runs the tasklet, could dma_do_tasklet() dereference the freed chan pointer and cause a use-after-free?
[Severity: High]
This is another pre-existing issue, but does fsldma_of_probe() ignore the return value of dma_async_device_register() just before this error path?
fsldma_of_probe() does this right before the out_free_fdev label:
dma_async_device_register(&fdev->common);
return 0;If dma_async_device_register() fails, the driver returns success but the device is not successfully registered. On driver teardown, fsldma_of_remove() will call dma_async_device_unregister() with this unregistered device.
Could this lead to a double-free or mis-free in the IDA allocator, freeing an ID it never successfully acquired and corrupting the DMA engine ID namespace?
Quoted 5 lines
drivers/dma/fsldma.c +0
-1} -irq_dispose_mapping (fdev->irq);iounmap (fdev->regs); out_free:kfree (fdev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 6 lines · Rosen Penev
Replace the per-controller
irq_of_parse_and_map()call withplatform_get_irq_optional(). The controller IRQ is optional when absent and the driver falls back to per-channel IRQs. The correspondingirq_dispose_mapping()calls in the probe error path and remove function are removed.
Quoted 6 lines
Moved before anything else in order to handle -EPROBE_DEFER and to avoid doing extra work. Simplifies the if statements as well.
Assisted-by LLMSigned-off-by Rosen Penev <[email protected]>---
Quoted 53 lines
v3: fix build error from the move
v2: move to the front of probe.drivers/dma/fsldma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/dma/fsldma.c +8
-4@@ -1224,8 +1224,13 @@ static int fsldma_of_probe(struct platform_device *op)struct fsldma_device *fdev;struct device_node *child;unsigned int i; +int irq;int err; + irq =platform_get_irq_optional (op,0 ); +if (irq == -EPROBE_DEFER ) +return irq; + fdev =kzalloc_obj (*fdev);if (!fdev) { err = -ENOMEM ;@@ -1246,7 +1251,9 @@ static int fsldma_of_probe(struct platform_device *op) }/* map the channel IRQ if it exists, but don't hookup the handler yet */ - fdev->irq =irq_of_parse_and_map (op->dev.of_node,0 ); + fdev->irq = irq; +if (fdev->irq <0 ) + fdev->irq =0 ;dma_cap_set (DMA_MEMCPY , fdev->common.cap_mask);dma_cap_set (DMA_SLAVE , fdev->common.cap_mask);@@ -1308,7 +1315,6 @@ static int fsldma_of_probe(struct platform_device *op)if (fdev->chan[i])fsl_dma_chan_remove (fdev->chan[i]); } -irq_dispose_mapping (fdev->irq);iounmap (fdev->regs); out_free:kfree (fdev);@@ -1330,7 +1336,6 @@ static void fsldma_of_remove(struct platform_device *op)if (fdev->chan[i])fsl_dma_chan_remove (fdev->chan[i]); } -irq_dispose_mapping (fdev->irq);iounmap (fdev->regs);kfree (fdev); --2.55.0
Quoted 10 lines · Rosen Penev
Replace the per-controller
irq_of_parse_and_map()call withplatform_get_irq_optional(). The controller IRQ is optional when absent and the driver falls back to per-channel IRQs. The correspondingirq_dispose_mapping()calls in the probe error path and remove function are removed.Moved before anything else in order to handle -EPROBE_DEFER and to avoid doing extra work. Simplifies the if statements as well.
[...]
Applied, thanks!
[1/1] dmaengine: fsldma: convert to platform_get_irq_optional()
commit: 0838d7cfa42536d2cdeb90074417fae33a2585a6
Best regards,
Signature · 1 line
~Vinod