From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc()
Date: Tue, 28 Jul 2026 17:34:45 +0000 [thread overview]
Message-ID: <20260728173446.353A21F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260728171523.112244-2-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing resource cleanup on error paths in switchtec_dma_alloc_chan_resources() causes memory leak of DMA descriptors and rings.
--
--- Patch [1]: [PATCH v4 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() ---
commit 5f9c3413d8c3e6b409c7cf9c3bd9dfaa071f19f6
Author: Logan Gunthorpe <logang@deltatee.com>
dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc()
This commit fixes a double-free in switchtec_dma_free_desc() by setting the
pointers to NULL after freeing them. This ensures that any subsequent calls
to the function are a no-op for resources that have already been released.
> If switchtec_dma_alloc_chan_resources() fails partway through and calls
> it during unwind, then a later retry of alloc_chan_resources() fails
> in switchtec_dma_alloc_desc() before reallocating one of those
[Severity: High]
This is a pre-existing issue, but does switchtec_dma_alloc_chan_resources()
actually call switchtec_dma_free_desc() during unwind?
If switchtec_dma_alloc_desc() succeeds, but a subsequent step fails:
drivers/dma/switchtec_dma.c:switchtec_dma_alloc_chan_resources() {
...
rc = switchtec_dma_alloc_desc(swdma_chan);
if (rc)
return rc;
rc = enable_channel(swdma_chan);
if (rc)
return rc;
rc = reset_channel(swdma_chan);
if (rc)
return rc;
rc = unhalt_channel(swdma_chan);
if (rc)
return rc;
...
}
It appears we return early without unwinding the allocations made by
switchtec_dma_alloc_desc(). Since the DMA engine core does not automatically
invoke device_free_chan_resources() when device_alloc_chan_resources()
fails, does this result in a permanent leak of the DMA descriptors and
rings?
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index 3ef9286406159..a4a7d66d042de 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
[ ... ]
> @@ -886,14 +886,18 @@ static void switchtec_dma_free_desc(struct switchtec_dma_chan *swdma_chan)
> if (swdma_chan->hw_sq)
> dma_free_coherent(swdma_dev->dma_dev.dev, size,
> swdma_chan->hw_sq, swdma_chan->dma_addr_sq);
> + swdma_chan->hw_sq = NULL;
>
> size = SWITCHTEC_DMA_CQ_SIZE * sizeof(*swdma_chan->hw_cq);
> if (swdma_chan->hw_cq)
> dma_free_coherent(swdma_dev->dma_dev.dev, size,
> swdma_chan->hw_cq, swdma_chan->dma_addr_cq);
> + swdma_chan->hw_cq = NULL;
>
> - for (i = 0; i < SWITCHTEC_DMA_RING_SIZE; i++)
> + for (i = 0; i < SWITCHTEC_DMA_RING_SIZE; i++) {
> kfree(swdma_chan->desc_ring[i]);
> + swdma_chan->desc_ring[i] = NULL;
> + }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728171523.112244-1-logang@deltatee.com?part=1
next prev parent reply other threads:[~2026-07-28 17:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 17:15 [PATCH v4 00/12] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-07-28 17:15 ` [PATCH v4 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-07-28 17:34 ` sashiko-bot [this message]
2026-07-28 17:15 ` [PATCH v4 02/12] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-07-28 17:40 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 03/12] dmaengine: switchtec-dma: always clear DMA base registers on chan_stop() Logan Gunthorpe
2026-07-28 17:34 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 04/12] dmaengine: switchtec-dma: halt channel on alloc_chan_resources error Logan Gunthorpe
2026-07-28 17:35 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 05/12] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-07-28 17:38 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 06/12] dmaengine: switchtec-dma: make switchtec_dma_chans_release() void Logan Gunthorpe
2026-07-28 17:44 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 07/12] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error Logan Gunthorpe
2026-07-28 17:39 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 08/12] dmaengine: switchtec-dma: disable channels before freeing on registration failure Logan Gunthorpe
2026-07-28 17:39 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 09/12] dmaengine: switchtec-dma: fix use-after-free of swdma_dev in remove() Logan Gunthorpe
2026-07-28 17:48 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 10/12] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-07-28 17:53 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 11/12] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-07-28 17:48 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-07-28 17:50 ` sashiko-bot
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=20260728173446.353A21F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.