From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: vkoul@kernel.org, dmaengine@vger.kernel.org, Frank.Li@kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v1 2/6] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources
Date: Fri, 17 Jul 2026 22:36:47 +0000 [thread overview]
Message-ID: <20260717223647.F0A051F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717221001.361421-3-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The error path in switchtec_dma_alloc_chan_resources() frees descriptor rings without halting the hardware channel or clearing DMA base addresses, leading to a potential DMA use-after-free.
--
--- Patch [2]: [PATCH v1 2/6] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources ---
commit eaf75ddb364eba320691aad49bebc8922067a94b
Author: Logan Gunthorpe <logang@deltatee.com>
dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources
This commit adds an error-unwind path to switchtec_dma_alloc_chan_resources()
to handle failures during initialization. It disables the channel and frees
the descriptor rings to prevent resource leaks when setup fails.
Link: https://lore.kernel.org/dmaengine/20260707165555.350951F000E9@smtp.kernel.org/T/#u
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
[ ... ]
> @@ -988,15 +988,15 @@ static int switchtec_dma_alloc_chan_resources(struct dma_chan *chan)
> rc = reset_channel(swdma_chan);
> if (rc)
> - return rc;
> + goto err_disable_channel;
>
> rc = unhalt_channel(swdma_chan);
> if (rc)
> - return rc;
> + goto err_disable_channel;
[ ... ]
> +err_ring_inactive:
> + spin_lock_bh(&swdma_chan->submit_lock);
> + swdma_chan->ring_active = false;
> + spin_unlock_bh(&swdma_chan->submit_lock);
> +
> + spin_lock_bh(&swdma_chan->complete_lock);
> + swdma_chan->comp_ring_active = false;
> + spin_unlock_bh(&swdma_chan->complete_lock);
> +err_disable_channel:
> + disable_channel(swdma_chan);
> +err_free_desc:
> + switchtec_dma_free_desc(swdma_chan);
> + return rc;
> }
[Severity: High]
If unhalt_channel() times out and returns an error, we jump here and free
the descriptor rings. Does this risk a DMA use-after-free?
Looking at disable_channel(), it merely clears an enable bit via a posted,
unflushed PCIe write. Because this unwind path skips switchtec_dma_chan_stop()
(which is used in the normal teardown path to synchronously halt the channel
and clear the base registers), couldn't the hardware complete the unhalt
command and access the descriptor rings right after they are freed?
Should this error path ensure the channel is fully stopped and DMA base
addresses are cleared before freeing the coherent DMA memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260717221001.361421-1-logang@deltatee.com?part=2
next prev parent reply other threads:[~2026-07-17 22:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 22:09 [PATCH v1 0/6] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-07-17 22:09 ` [PATCH v1 1/6] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-07-17 22:30 ` sashiko-bot
2026-07-17 22:09 ` [PATCH v1 2/6] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-07-17 22:36 ` sashiko-bot [this message]
2026-07-17 22:09 ` [PATCH v1 3/6] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-07-17 22:34 ` sashiko-bot
2026-07-17 22:09 ` [PATCH v1 4/6] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-07-17 22:34 ` sashiko-bot
2026-07-17 22:10 ` [PATCH v1 5/6] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-07-17 22:35 ` sashiko-bot
2026-07-17 22:10 ` [PATCH v1 6/6] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-07-17 22:32 ` 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=20260717223647.F0A051F000E9@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.