From: sashiko-bot@kernel.org
To: Frank.Li@oss.nxp.com
Cc: dmaengine@vger.kernel.org, linux-pci@vger.kernel.org,
imx@lists.linux.dev, Frank.Li@kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v6 8/9] PCI: epf-mhi: Use dmaengine_prep_config_single() to simplify code
Date: Thu, 21 May 2026 02:08:13 +0000 [thread overview]
Message-ID: <20260521020814.53ACC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260520-dma_prep_config-v6-8-06e49b7acb38@nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The DMA workqueue is destroyed before pending DMA transfers are explicitly terminated, which can lead to a Use-After-Free if a DMA callback executes late.
--
commit 01fd36b3138418658a89651874d85c30619199e8
Author: Frank Li <Frank.Li@nxp.com>
PCI: epf-mhi: Use dmaengine_prep_config_single() to simplify code
This commit replaces dmaengine_slave_config() and dmaengine_prep_slave_single()
with a single call to dmaengine_prep_config_single() in the EDMA read and write
paths. The change aims to simplify the code without introducing any functional
differences.
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 7f5326925ed54..c3e3b58fb86cd 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
[ ... ]
> @@ -506,12 +496,6 @@ static int pci_epf_mhi_edma_read_async(struct mhi_ep_cntrl *mhi_cntrl,
> config.direction = DMA_DEV_TO_MEM;
> config.src_addr = buf_info->host_addr;
>
> - ret = dmaengine_slave_config(chan, &config);
> - if (ret) {
> - dev_err(dev, "Failed to configure DMA channel\n");
> - goto err_unlock;
> - }
> -
> dst_addr = dma_map_single(dma_dev, buf_info->dev_addr, buf_info->size,
> DMA_FROM_DEVICE);
> ret = dma_mapping_error(dma_dev, dst_addr);
> @@ -520,9 +504,10 @@ static int pci_epf_mhi_edma_read_async(struct mhi_ep_cntrl *mhi_cntrl,
> goto err_unlock;
> }
>
> - desc = dmaengine_prep_slave_single(chan, dst_addr, buf_info->size,
> - DMA_DEV_TO_MEM,
> - DMA_CTRL_ACK | DMA_PREP_INTERRUPT);
> + desc = dmaengine_prep_config_single(chan, dst_addr, buf_info->size,
> + DMA_DEV_TO_MEM,
> + DMA_CTRL_ACK | DMA_PREP_INTERRUPT,
> + &config);
[Severity: High]
This is a pre-existing issue, but I noticed a potential problem with how these
asynchronous DMA transfers are cleaned up.
In pci_epf_mhi_dma_deinit(), the DMA workqueue is destroyed before pending DMA
transfers are explicitly terminated:
static void pci_epf_mhi_dma_deinit(struct pci_epf_mhi *epf_mhi)
{
destroy_workqueue(epf_mhi->dma_wq);
dma_release_channel(epf_mhi->dma_chan_tx);
dma_release_channel(epf_mhi->dma_chan_rx);
...
}
Does this sequence lead to a use-after-free if a DMA callback executes late?
If a transfer is physically still running in the DMA engine hardware when the
deinitialization begins, destroy_workqueue() will flush existing queued work
but cannot stop the hardware itself.
If the hardware completes the transfer a moment later, the DMA engine
interrupt will fire and invoke pci_epf_mhi_dma_async_callback(), which
blindly calls queue_work(epf_mhi->dma_wq, ...).
Should dmaengine_terminate_sync() be called to abort pending asynchronous
DMA transfers on all active channels before destroying the workqueue?
> if (!desc) {
> dev_err(dev, "Failed to prepare DMA\n");
> ret = -EIO;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260520-dma_prep_config-v6-0-06e49b7acb38@nxp.com?part=8
next prev parent reply other threads:[~2026-05-21 2:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 22:00 [PATCH v6 0/9] dmaengine: Add new API to combine configuration and descriptor preparation Frank.Li
2026-05-20 22:00 ` [PATCH v6 1/9] dmaengine: Add API to combine configuration and preparation (sg and single) Frank.Li
2026-05-20 22:00 ` [PATCH v6 2/9] dmaengine: Add safe API to combine configuration and preparation Frank.Li
2026-05-21 0:01 ` sashiko-bot
2026-05-21 14:56 ` Frank Li
2026-05-20 22:00 ` [PATCH v6 3/9] PCI: endpoint: pci-epf-test: Use dmaenigne_prep_config_single() to simplify code Frank.Li
2026-05-20 22:00 ` [PATCH v6 4/9] dmaengine: dw-edma: Use new .device_prep_config_sg() callback Frank.Li
2026-05-21 0:31 ` sashiko-bot
2026-05-21 14:59 ` Frank Li
2026-05-20 22:00 ` [PATCH v6 5/9] dmaengine: dw-edma: Pass dma_slave_config to dw_edma_device_transfer() Frank.Li
2026-05-21 0:51 ` sashiko-bot
2026-05-21 15:02 ` Frank Li
2026-05-20 22:00 ` [PATCH v6 6/9] nvmet: pci-epf: Remove unnecessary dmaengine_terminate_sync() on each DMA transfer Frank.Li
2026-05-20 22:00 ` [PATCH v6 7/9] nvmet: pci-epf: Use dmaengine_prep_config_single_safe() API Frank.Li
2026-05-21 1:39 ` sashiko-bot
2026-05-21 15:08 ` Frank Li
2026-05-20 22:00 ` [PATCH v6 8/9] PCI: epf-mhi: Use dmaengine_prep_config_single() to simplify code Frank.Li
2026-05-21 2:08 ` sashiko-bot [this message]
2026-05-21 15:09 ` Frank Li
2026-05-20 22:00 ` [PATCH v6 9/9] crypto: atmel: Use dmaengine_prep_config_sg() API Frank.Li
2026-05-21 2:33 ` sashiko-bot
2026-05-21 15:11 ` Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260521020814.53ACC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=Frank.Li@oss.nxp.com \
--cc=dmaengine@vger.kernel.org \
--cc=imx@lists.linux.dev \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox