* [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ
@ 2026-08-30 5:33 Runyu Xiao
2026-08-30 5:47 ` sashiko-bot
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Runyu Xiao @ 2026-08-30 5:33 UTC (permalink / raw)
To: adrian.ho.yin.ng
Cc: sr, vkoul, Frank.Li, dmaengine, linux-kernel, stable, runyu.xiao,
jianhao.xu
msgdma_probe() registers the IRQ before initializing the tasklet, lock,
and descriptor lists used by the interrupt handler. A pending interrupt
can access incomplete state during probe.
Initialize the handler state before requesting the IRQ so the interrupt
path observes ready software state.
Fixes: a85c6f1b2921 ("dmaengine: Add driver for Altera / Intel mSGDMA IP core")
Cc: stable@vger.kernel.org
Assisted-by: Codex:GPT-5
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
drivers/dma/altera-msgdma.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/dma/altera-msgdma.c b/drivers/dma/altera-msgdma.c
index e23e5b441..412f4bce1 100644
--- a/drivers/dma/altera-msgdma.c
+++ b/drivers/dma/altera-msgdma.c
@@ -847,11 +847,6 @@ static int msgdma_probe(struct platform_device *pdev)
if (mdev->irq < 0)
return -ENXIO;
- ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
- 0, dev_name(&pdev->dev), mdev);
- if (ret)
- return ret;
-
tasklet_setup(&mdev->irq_tasklet, msgdma_tasklet);
dma_cookie_init(&mdev->dmachan);
@@ -863,6 +858,11 @@ static int msgdma_probe(struct platform_device *pdev)
INIT_LIST_HEAD(&mdev->done_list);
INIT_LIST_HEAD(&mdev->free_list);
+ ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
+ 0, dev_name(&pdev->dev), mdev);
+ if (ret)
+ return ret;
+
dma_dev = &mdev->dmadev;
/* Set DMA capabilities */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ
2026-08-30 5:33 [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ Runyu Xiao
@ 2026-08-30 5:47 ` sashiko-bot
2026-08-31 15:50 ` Frank Li
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-08-30 5:47 UTC (permalink / raw)
To: Runyu Xiao; +Cc: Frank.Li, vkoul, dmaengine
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing dma_async_device_unregister() on the of_dma_controller_register() error path causes a use-after-free in the DMA framework.
- [High] IRQ is requested before the hardware is properly reset and quiesced, leaving a race window that can cause an interrupt storm or concurrent hardware access during reset.
- [High] Chained DMA transactions are stalled forever because msgdma_start_transfer() moves all pending transactions to active_list but only submits the first one to the hardware.
- [High] Hardware interrupts are enabled at probe but never disabled in the error path or during module removal, risking an IRQ storm.
--
commit 7387a0714cc7c9797e08cd9d4ea5b72695584890
Author: Runyu Xiao <runyu.xiao@seu.edu.cn>
dmaengine: altera-msgdma: initialize state before requesting IRQ
msgdma_probe() registers the IRQ before initializing the tasklet, lock,
and descriptor lists used by the interrupt handler. A pending interrupt
can access incomplete state during probe.
> diff --git a/drivers/dma/altera-msgdma.c b/drivers/dma/altera-msgdma.c
> index e23e5b441a24e..412f4bce1d4aa 100644
> --- a/drivers/dma/altera-msgdma.c
> +++ b/drivers/dma/altera-msgdma.c
> @@ -847,11 +847,6 @@ static int msgdma_probe(struct platform_device *pdev)
> if (mdev->irq < 0)
> return -ENXIO;
>
> - ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> - 0, dev_name(&pdev->dev), mdev);
> - if (ret)
> - return ret;
> -
> tasklet_setup(&mdev->irq_tasklet, msgdma_tasklet);
>
> dma_cookie_init(&mdev->dmachan);
> @@ -863,6 +858,11 @@ static int msgdma_probe(struct platform_device *pdev)
> INIT_LIST_HEAD(&mdev->done_list);
> INIT_LIST_HEAD(&mdev->free_list);
>
> + ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> + 0, dev_name(&pdev->dev), mdev);
> + if (ret)
> + return ret;
> +
[Severity: High]
This isn't a bug introduced by this patch, but the IRQ is still being
requested before msgdma_reset() is called to quiesce the hardware.
If the bootloader left the device active, can it fire an interrupt
immediately upon registration?
If this happens, the interrupt handler might access hardware registers and
schedule the tasklet while the probe routine concurrently writes to reset
bits in msgdma_reset(), potentially causing bus hangs or an IRQ storm.
Should the hardware be quiesced before registering the IRQ?
[Severity: High]
This is a pre-existing issue, but does the probe error path leak the async
DMA device if registration fails?
If of_dma_controller_register() fails, the code jumps to the cleanup path:
drivers/dma/altera-msgdma.c:msgdma_probe() {
...
} else if (ret && ret != -ENODEV) {
goto fail;
}
...
fail:
msgdma_dev_remove(mdev);
return ret;
}
However, msgdma_dev_remove() omits deregistering the async device:
drivers/dma/altera-msgdma.c:msgdma_dev_remove() {
if (!mdev)
return;
devm_free_irq(mdev->dev, mdev->irq, mdev);
tasklet_kill(&mdev->irq_tasklet);
list_del(&mdev->dmachan.device_node);
}
Because mdev is allocated with devm_kzalloc(), it gets freed upon probe
failure, leaving the dmaengine subsystem with pointers to a freed
dma_device. Could this result in a use-after-free?
[Severity: High]
This isn't a bug introduced by this patch, but are hardware interrupts left
enabled if probe fails or the module is removed?
msgdma_reset() explicitly enables interrupts on the hardware:
drivers/dma/altera-msgdma.c:msgdma_reset() {
...
iowrite32(MSGDMA_CSR_CTL_STOP_ON_ERR | MSGDMA_CSR_CTL_STOP_ON_EARLY |
MSGDMA_CSR_CTL_GLOBAL_INTR, mdev->csr + MSGDMA_CSR_CONTROL);
...
}
If an error occurs after resetting (e.g., during dma_async_device_register),
the cleanup path calls msgdma_dev_remove(), which frees the OS IRQ handler
but fails to write back to MSGDMA_CSR_CONTROL to disable the hardware-level
interrupts.
Could this leave the hardware capable of asserting the IRQ line without a
registered handler, leading to an unhandled IRQ storm?
[Severity: High]
This is a pre-existing issue, but are chained DMA transactions stalled
indefinitely when using this driver?
When msgdma_start_transfer() is called, it moves all pending transactions to
the active list, but only submits the first one to the hardware:
drivers/dma/altera-msgdma.c:msgdma_start_transfer() {
...
list_splice_tail_init(&mdev->pending_list, &mdev->active_list);
msgdma_copy_desc_to_fifo(mdev, desc);
...
}
Once the hardware finishes the first transaction, the interrupt handler fires
and calls msgdma_start_transfer() to initiate the next transfer. However, it
then checks the pending list instead of the active list:
drivers/dma/altera-msgdma.c:msgdma_start_transfer() {
desc = list_first_entry_or_null(&mdev->pending_list,
struct msgdma_sw_desc, node);
if (!desc)
return;
...
}
Since the pending list is empty from the prior splice, does it abandon the
remaining transactions in the active list and stall the pipeline?
> dma_dev = &mdev->dmadev;
>
> /* Set DMA capabilities */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260830053308.2190597-1-runyu.xiao@seu.edu.cn?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ
2026-08-30 5:33 [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ Runyu Xiao
2026-08-30 5:47 ` sashiko-bot
@ 2026-08-31 15:50 ` Frank Li
2026-09-01 7:21 ` Ng, Adrian Ho Yin
2026-09-09 12:41 ` Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Frank Li @ 2026-08-31 15:50 UTC (permalink / raw)
To: Runyu Xiao
Cc: adrian.ho.yin.ng, sr, vkoul, Frank.Li, dmaengine, linux-kernel,
stable, jianhao.xu
On Sun, Aug 30, 2026 at 01:33:08PM +0800, Runyu Xiao wrote:
> msgdma_probe() registers the IRQ before initializing the tasklet, lock,
> and descriptor lists used by the interrupt handler. A pending interrupt
> can access incomplete state during probe.
>
> Initialize the handler state before requesting the IRQ so the interrupt
> path observes ready software state.
>
> Fixes: a85c6f1b2921 ("dmaengine: Add driver for Altera / Intel mSGDMA IP core")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:GPT-5
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/dma/altera-msgdma.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma/altera-msgdma.c b/drivers/dma/altera-msgdma.c
> index e23e5b441..412f4bce1 100644
> --- a/drivers/dma/altera-msgdma.c
> +++ b/drivers/dma/altera-msgdma.c
> @@ -847,11 +847,6 @@ static int msgdma_probe(struct platform_device *pdev)
> if (mdev->irq < 0)
> return -ENXIO;
>
> - ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> - 0, dev_name(&pdev->dev), mdev);
> - if (ret)
> - return ret;
> -
> tasklet_setup(&mdev->irq_tasklet, msgdma_tasklet);
>
> dma_cookie_init(&mdev->dmachan);
> @@ -863,6 +858,11 @@ static int msgdma_probe(struct platform_device *pdev)
> INIT_LIST_HEAD(&mdev->done_list);
> INIT_LIST_HEAD(&mdev->free_list);
>
> + ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> + 0, dev_name(&pdev->dev), mdev);
> + if (ret)
> + return ret;
> +
> dma_dev = &mdev->dmadev;
>
> /* Set DMA capabilities */
> --
> 2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ
2026-08-30 5:33 [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ Runyu Xiao
2026-08-30 5:47 ` sashiko-bot
2026-08-31 15:50 ` Frank Li
@ 2026-09-01 7:21 ` Ng, Adrian Ho Yin
2026-09-09 12:41 ` Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Ng, Adrian Ho Yin @ 2026-09-01 7:21 UTC (permalink / raw)
To: Runyu Xiao
Cc: sr, vkoul, Frank.Li, dmaengine, linux-kernel, stable, jianhao.xu
On 8/30/2026 1:33 PM, Runyu Xiao wrote:
> msgdma_probe() registers the IRQ before initializing the tasklet, lock,
> and descriptor lists used by the interrupt handler. A pending interrupt
> can access incomplete state during probe.
>
> Initialize the handler state before requesting the IRQ so the interrupt
> path observes ready software state.
>
> Fixes: a85c6f1b2921 ("dmaengine: Add driver for Altera / Intel mSGDMA IP core")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:GPT-5
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> ---
Acked-by: Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>
> drivers/dma/altera-msgdma.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma/altera-msgdma.c b/drivers/dma/altera-msgdma.c
> index e23e5b441..412f4bce1 100644
> --- a/drivers/dma/altera-msgdma.c
> +++ b/drivers/dma/altera-msgdma.c
> @@ -847,11 +847,6 @@ static int msgdma_probe(struct platform_device *pdev)
> if (mdev->irq < 0)
> return -ENXIO;
>
> - ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> - 0, dev_name(&pdev->dev), mdev);
> - if (ret)
> - return ret;
> -
> tasklet_setup(&mdev->irq_tasklet, msgdma_tasklet);
>
> dma_cookie_init(&mdev->dmachan);
> @@ -863,6 +858,11 @@ static int msgdma_probe(struct platform_device *pdev)
> INIT_LIST_HEAD(&mdev->done_list);
> INIT_LIST_HEAD(&mdev->free_list);
>
> + ret = devm_request_irq(&pdev->dev, mdev->irq, msgdma_irq_handler,
> + 0, dev_name(&pdev->dev), mdev);
> + if (ret)
> + return ret;
> +
> dma_dev = &mdev->dmadev;
>
> /* Set DMA capabilities */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ
2026-08-30 5:33 [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ Runyu Xiao
` (2 preceding siblings ...)
2026-09-01 7:21 ` Ng, Adrian Ho Yin
@ 2026-09-09 12:41 ` Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2026-09-09 12:41 UTC (permalink / raw)
To: adrian.ho.yin.ng, Runyu Xiao
Cc: sr, Frank.Li, dmaengine, linux-kernel, stable, jianhao.xu
On Sun, 30 Aug 2026 13:33:08 +0800, Runyu Xiao wrote:
> msgdma_probe() registers the IRQ before initializing the tasklet, lock,
> and descriptor lists used by the interrupt handler. A pending interrupt
> can access incomplete state during probe.
>
> Initialize the handler state before requesting the IRQ so the interrupt
> path observes ready software state.
>
> [...]
Applied, thanks!
[1/1] dmaengine: altera-msgdma: initialize state before requesting IRQ
commit: 4cfa625b60d55b81bc6620113f213349bcc85a4e
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-09 12:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-30 5:33 [PATCH] dmaengine: altera-msgdma: initialize state before requesting IRQ Runyu Xiao
2026-08-30 5:47 ` sashiko-bot
2026-08-31 15:50 ` Frank Li
2026-09-01 7:21 ` Ng, Adrian Ho Yin
2026-09-09 12:41 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox