From: sashiko-bot@kernel.org
To: "Pan Chuang" <panchuang@vivo.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 03/26] dmaengine: loongson-loongson1-apb-dma: Remove redundant dev_err()/dev_err_probe()
Date: Thu, 09 Jul 2026 14:11:30 +0000 [thread overview]
Message-ID: <20260709141131.796011F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260709135846.97972-4-panchuang@vivo.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cleanup of devm-managed IRQ on error paths inside ls1x_dma_alloc_chan_resources() leading to persistent leaks.
- [High] Unsafe IRQF_SHARED handler lacks hardware status verification, risking data corruption.
- [High] API violation: non-atomic readl_poll_timeout macro used in atomic context risks hard lockups.
- [High] Incorrect use of the logical sysfs channel device for DMA API operations and devres allocations.
- [High] Bypassing the devres unregister mechanism causes a Use-After-Free and resource leaks.
- [High] Memory for the DMA descriptor is leaked if scatterlist allocation fails in ls1x_dma_prep_dma_cyclic().
--
--- Patch [3]: [PATCH 03/26] dmaengine: loongson-loongson1-apb-dma: Remove redundant dev_err()/dev_err_probe() ---
commit cc0e2dcbd30ac2febb8a1c6ef2b34cbde416aa33
Author: Pan Chuang <panchuang@vivo.com>
dmaengine: loongson-loongson1-apb-dma: Remove redundant dev_err()/dev_err_probe()
This commit removes redundant dev_err() calls when devm_request_irq() fails in
ls1x_dma_alloc_chan_resources(). Since devm_request_irq() logs its own detailed
error messages, the driver-specific messages are no longer needed.
> diff --git a/drivers/dma/loongson/loongson1-apb-dma.c b/drivers/dma/loongson/loongson1-apb-dma.c
> index 89786cbd20ab5..812bd7c2068f9 100644
> --- a/drivers/dma/loongson/loongson1-apb-dma.c
> +++ b/drivers/dma/loongson/loongson1-apb-dma.c
> @@ -162,10 +162,8 @@ static int ls1x_dma_alloc_chan_resources(struct dma_chan *dchan)
>
> ret = devm_request_irq(dev, chan->irq, ls1x_dma_irq_handler,
> IRQF_SHARED, dma_chan_name(dchan), chan);
> - if (ret) {
> - dev_err(dev, "failed to request IRQ %d\n", chan->irq);
> + if (ret)
> return ret;
> - }
>
> chan->lli_pool = dma_pool_create(dma_chan_name(dchan), dev,
> sizeof(struct ls1x_dma_lli),
> __alignof__(struct ls1x_dma_lli), 0);
> if (!chan->lli_pool)
> return -ENOMEM;
>
> /* allocate memory for querying the current lli */
> dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
> chan->curr_lli = dma_alloc_coherent(dev, sizeof(struct ls1x_dma_lli),
> &phys, GFP_KERNEL);
> if (!chan->curr_lli) {
> dma_pool_destroy(chan->lli_pool);
> return -ENOMEM;
> }
[Severity: High]
This is a pre-existing issue, but is the devm-managed IRQ leaked on this
error path?
If dma_pool_create() or dma_alloc_coherent() fails, we return -ENOMEM without
freeing the IRQ requested via devm_request_irq().
The devm-managed cleanup won't happen because the channel's sysfs device is not
destroyed, leading to local clients hitting -EBUSY on subsequent allocation
attempts.
[ ... ]
> static inline struct device *chan2dev(struct dma_chan *chan)
> {
> return &chan->dev->device;
> }
[Severity: High]
This isn't a bug introduced by this patch, but should this helper be returning
the hardware platform device instead?
This macro returns the logical sysfs channel device instead of the hardware
platform device (dchan->device->dev). Passing this logical device to DMA API
operations like dma_alloc_coherent() or dma_pool_create() can cause allocation
failures or incorrect mappings on platforms with strict DMA tracking or an
IOMMU.
[ ... ]
> static inline int ls1x_dma_start(struct ls1x_dma_chan *chan,
> dma_addr_t *lli_phys)
> {
[ ... ]
> ret = readl_poll_timeout(chan->reg_base + LS1X_DMA_CTRL, val,
> !(val & LS1X_DMA_START), 0, 1000);
[Severity: High]
This is a pre-existing issue, but does using readl_poll_timeout() here risk
hard lockups?
ls1x_dma_start() is called from ls1x_dma_resume() and ls1x_dma_issue_pending()
with the channel's lock held and interrupts disabled:
ls1x_dma_resume()
guard(spinlock_irqsave)(&chan->vc.lock);
return ls1x_dma_start(chan, &chan->curr_lli->phys);
Using the non-atomic readl_poll_timeout() macro in an atomic context is unsafe
because timekeeping might be suspended, causing the internal ktime_get() to
stall or return invalid values.
[ ... ]
> static struct dma_async_tx_descriptor *
> ls1x_dma_prep_dma_cyclic(struct dma_chan *dchan, dma_addr_t buf_addr,
[ ... ]
> desc = ls1x_dma_alloc_desc();
> if (!desc)
> return NULL;
>
> /* allocate the scatterlist */
> sg_len = buf_len / period_len;
> sgl = kmalloc_objs(*sgl, sg_len, GFP_NOWAIT);
> if (!sgl)
> return NULL;
[Severity: High]
This isn't a bug introduced by this patch, but what happens to the allocated
descriptor if kmalloc_objs() fails?
If we fail to allocate the scatterlist, the function returns NULL without
freeing the desc allocated just above it, resulting in a memory leak.
[ ... ]
> static irqreturn_t ls1x_dma_irq_handler(int irq, void *data)
> {
[ ... ]
> scoped_guard(spinlock, &chan->vc.lock) {
> vd = vchan_next_desc(&chan->vc);
> if (!vd) {
> dev_warn(dev,
> "IRQ %d with no active desc on channel %d\n",
> irq, dchan->chan_id);
> return IRQ_NONE;
> }
[Severity: High]
This is a pre-existing issue, but is it safe for a shared IRQ handler to
assume ownership of the interrupt without checking hardware status?
The handler is registered with IRQF_SHARED, but it processes active descriptors
purely based on whether one is queued in software. If another device sharing
the IRQ line triggers an interrupt, this could prematurely complete the current
in-flight DMA transfer and cause data corruption.
[ ... ]
> static void ls1x_dma_chan_remove(struct ls1x_dma *dma)
> {
> int id;
>
> for (id = 0; id < dma->nr_chans; id++) {
> struct ls1x_dma_chan *chan = &dma->chan[id];
>
> if (chan->vc.chan.device == &dma->ddev) {
> list_del(&chan->vc.chan.device_node);
> tasklet_kill(&chan->vc.task);
> }
> }
> }
[Severity: High]
This isn't a bug introduced by this patch, but will deleting the channel from
the list here bypass the devres unregister mechanism?
During module removal or probe failure, manually calling list_del() orphans
the channel from the dmaengine core. When devres later runs
dma_async_device_unregister(), it iterates over an empty list and fails to
unregister the channels.
This permanently leaks the sysfs channel devices and percpu memory, and will
trigger a Use-After-Free when the underlying struct ls1x_dma is freed by
devm_kzalloc cleanup.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709135846.97972-1-panchuang@vivo.com?part=3
next prev parent reply other threads:[~2026-07-09 14:11 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 13:58 [PATCH 00/26] dmaengine: Remove redundant error messages on IRQ request failure Pan Chuang
2026-07-09 13:58 ` [PATCH 01/26] dmaengine: fsl-edma-main: Remove redundant dev_err()/dev_err_probe() Pan Chuang
2026-07-09 14:12 ` sashiko-bot
2026-07-09 14:33 ` Frank Li
2026-07-09 13:58 ` [PATCH 02/26] dmaengine: fsl-qdma: " Pan Chuang
2026-07-09 14:08 ` sashiko-bot
2026-07-09 14:34 ` Frank Li
2026-07-09 13:58 ` [PATCH 03/26] dmaengine: loongson-loongson1-apb-dma: " Pan Chuang
2026-07-09 14:11 ` sashiko-bot [this message]
2026-07-09 13:58 ` [PATCH 04/26] dmaengine: mediatek-mtk-cqdma: " Pan Chuang
2026-07-09 14:10 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 05/26] dmaengine: mediatek-mtk-hsdma: " Pan Chuang
2026-07-09 14:10 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 06/26] dmaengine: mmp_pdma: " Pan Chuang
2026-07-09 14:08 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 07/26] dmaengine: moxart-dma: " Pan Chuang
2026-07-09 14:16 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 08/26] dmaengine: owl-dma: " Pan Chuang
2026-07-09 14:16 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 09/26] dmaengine: pxa_dma: " Pan Chuang
2026-07-09 14:20 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 10/26] dmaengine: qcom-gpi: " Pan Chuang
2026-07-09 14:19 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 11/26] dmaengine: sf-pdma-sf-pdma: " Pan Chuang
2026-07-09 14:18 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 12/26] dmaengine: sh-rcar-dmac: " Pan Chuang
2026-07-09 14:23 ` sashiko-bot
2026-07-09 14:31 ` Geert Uytterhoeven
2026-07-09 13:58 ` [PATCH 13/26] dmaengine: sh-rz-dmac: " Pan Chuang
2026-07-09 14:32 ` Geert Uytterhoeven
2026-07-09 13:58 ` [PATCH 14/26] dmaengine: sh-shdmac: " Pan Chuang
2026-07-09 14:24 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 15/26] dmaengine: sh-usb-dmac: " Pan Chuang
2026-07-09 14:27 ` sashiko-bot
2026-07-09 14:33 ` Geert Uytterhoeven
2026-07-09 13:58 ` [PATCH 16/26] dmaengine: sprd-dma: " Pan Chuang
2026-07-09 14:27 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 17/26] dmaengine: st_fdma: " Pan Chuang
2026-07-09 14:30 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 18/26] dmaengine: stm32-stm32-dma: " Pan Chuang
2026-07-09 14:30 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 19/26] dmaengine: stm32-stm32-dma3: " Pan Chuang
2026-07-09 14:33 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 20/26] dmaengine: stm32-stm32-mdma: " Pan Chuang
2026-07-09 14:32 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 21/26] dmaengine: sun4i-dma: " Pan Chuang
2026-07-09 14:35 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 22/26] dmaengine: sun6i-dma: " Pan Chuang
2026-07-09 13:58 ` [PATCH 23/26] dmaengine: tegra20-apb-dma: " Pan Chuang
2026-07-09 13:58 ` [PATCH 24/26] dmaengine: ti-edma: " Pan Chuang
2026-07-09 14:38 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 25/26] dmaengine: uniphier-xdmac: " Pan Chuang
2026-07-09 14:41 ` sashiko-bot
2026-07-09 13:58 ` [PATCH 26/26] dmaengine: xgene-dma: " Pan Chuang
2026-07-09 14:39 ` sashiko-bot
2026-07-09 14:26 ` [PATCH 00/26] dmaengine: Remove redundant error messages on IRQ request failure Wolfram Sang
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=20260709141131.796011F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=panchuang@vivo.com \
--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