[PATCH v2 03/11] dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()

From: Lee Jones

Date: Tue Nov 17 2026 - 11:39:19 EST


ae4_core_init() registers the DMA device and creates the descriptor slab
cache via pt_dmaengine_register(), but ae4_pci_remove() never undoes
either, leaking the descriptor cache and leaving a dangling DMA device
registered after device removal.

Unregister the DMA device first, so that no channels remain available to
clients, then stop the per-queue completion work, which may still free
descriptors into the cache, and only then destroy the descriptor cache.
pt_dmaengine_unregister() is open-coded here because it destroys the
cache immediately after unregistering, before the completion work has
been stopped.

Unregistering the DMA device also removes the ptdma debugfs entries,
which were previously left behind after removal, pointing at freed
device data.

Fixes: 98f5a4432622 ("dmaengine: ae4dma: Register AE4DMA using pt_dmaengine_register")
Closes: https://sashiko.dev/#/bug/linux-10d41112-e133-4bc5-8e53-b3e96592c70d
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

v1 => v2:
- Stop the completion work before destroying the descriptor cache
- Open-code the unregistration rather than exporting pt_dmaengine_unregister()

drivers/dma/amd/ae4dma/ae4dma-pci.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/dma/amd/ae4dma/ae4dma-pci.c b/drivers/dma/amd/ae4dma/ae4dma-pci.c
index 2c63907db228..b97fd37bb87d 100644
--- a/drivers/dma/amd/ae4dma/ae4dma-pci.c
+++ b/drivers/dma/amd/ae4dma/ae4dma-pci.c
@@ -131,8 +131,14 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
static void ae4_pci_remove(struct pci_dev *pdev)
{
struct ae4_device *ae4 = dev_get_drvdata(&pdev->dev);
+ struct pt_device *pt = &ae4->pt;

+ dma_async_device_unregister(&pt->dma_dev);
+
+ /* Completion processing frees descriptors into the cache, so stop it first */
ae4_destroy_work(ae4);
+ kmem_cache_destroy(pt->dma_desc_cache);
+
ae4_deinit(ae4);
}

--
2.56.0.679.gc527c65306-goog