Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
@ 2026-11-18 14:16 Guangshuo Li
  2026-11-18 14:31 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:16 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-arm-msm, linux-sound, linux-kernel, stable

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@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:16 [PATCH] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown Guangshuo Li
2026-11-18 14:31 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox