[PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
From: srini
Date: Tue Dec 01 2026 - 18:28:39 EST
From: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
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>
Signed-off-by: Srinivas Kandagatla <srini@xxxxxxxxxx>
---
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 8da75c4b50e5..a29e57303046 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);
}
--
2.53.0