[PATCH] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
From: Guangshuo Li
Date: Wed Nov 18 2026 - 09:17:09 EST
DMA teardown terminates transfers and releases the channels but leaves
the coherent message buffers allocated. A subsequent initialization
overwrites their addresses, and removal loses them permanently.
Free the buffers after terminating DMA. Clear channels released during
initialization failure so teardown cannot free the same resources again.
This issue was found by our static analysis tool under development.
Fixes: 917809e2280b ("slimbus: ngd: Add qcom SLIMBus NGD driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/slimbus/qcom-ngd-ctrl.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
index eb983b6d1815..e604f4e2b762 100644
--- a/drivers/slimbus/qcom-ngd-ctrl.c
+++ b/drivers/slimbus/qcom-ngd-ctrl.c
@@ -706,9 +706,12 @@ static int qcom_slim_ngd_init_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl)
return 0;
rx_post_err:
+ dmaengine_terminate_sync(ctrl->dma_rx_channel);
dma_free_coherent(dev, size, ctrl->rx_base, ctrl->rx_phys_base);
+ ctrl->rx_base = NULL;
rel_rx:
dma_release_channel(ctrl->dma_rx_channel);
+ ctrl->dma_rx_channel = NULL;
return ret;
}
@@ -743,6 +746,7 @@ static int qcom_slim_ngd_init_tx_msgq(struct qcom_slim_ngd_ctrl *ctrl)
return 0;
rel_tx:
dma_release_channel(ctrl->dma_tx_channel);
+ ctrl->dma_tx_channel = NULL;
return ret;
}
@@ -1210,11 +1214,19 @@ static int qcom_slim_ngd_exit_dma(struct qcom_slim_ngd_ctrl *ctrl)
{
if (ctrl->dma_rx_channel) {
dmaengine_terminate_sync(ctrl->dma_rx_channel);
+ dma_free_coherent(ctrl->dev,
+ QCOM_SLIM_NGD_DESC_NUM * SLIM_MSGQ_BUF_LEN,
+ ctrl->rx_base, ctrl->rx_phys_base);
+ ctrl->rx_base = NULL;
dma_release_channel(ctrl->dma_rx_channel);
}
if (ctrl->dma_tx_channel) {
dmaengine_terminate_sync(ctrl->dma_tx_channel);
+ dma_free_coherent(ctrl->dev,
+ (QCOM_SLIM_NGD_DESC_NUM + 1) * SLIM_MSGQ_BUF_LEN,
+ ctrl->tx_base, ctrl->tx_phys_base);
+ ctrl->tx_base = NULL;
dma_release_channel(ctrl->dma_tx_channel);
}
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0