Skip to contentSkip to conversation

tty: serial: fsl_lpuart: avoid releasing DMA channels twice

PATCH In review Yige Jiang 3 participants 3 messages Nov 29 – Dec 1

Subsystems (2)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH 1/1 tty: serial: fsl_lpuart: avoid releasing DMA channels twice

lpuart_dma_shutdown() releases the TX and RX DMA channels but leaves their pointers set. If the device is removed after port shutdown, lpuart_remove() passes the same channels to dma_release_channel() again. This can trigger a DMAengine channel reference count warning.

Clear each channel pointer after releasing it so that lpuart_remove() only releases channels the driver still owns.

A tool-assisted lifetime review found the extra release. Codex helped draft the fix and this commit message.

Fixes 159381df1442 ("tty: serial: fsl_lpuart: fix DMA operation when using IOMMU")

---
Compile-tested on arm64 defconfig with GCC 14.2 and W=1.

 drivers/tty/serial/fsl_lpuart.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c +7 -2
index e54b4c44db42..17a67805b208 100644
@@ -1934,10 +1934,15 @@ static void lpuart_dma_shutdown(struct lpuart_port *sport)
 		sport->lpuart_dma_tx_use = false;
 	}
 
-	if (sport->dma_tx_chan)
+	if (sport->dma_tx_chan) {
 		dma_release_channel(sport->dma_tx_chan);
-	if (sport->dma_rx_chan)
+		sport->dma_tx_chan = NULL;
+	}
+
+	if (sport->dma_rx_chan) {
 		dma_release_channel(sport->dma_rx_chan);
+		sport->dma_rx_chan = NULL;
+	}
 }
 
 static void lpuart_shutdown(struct uart_port *port)

base-commit: eedf2cf3505c1562a2fb24f8b997056f023d242b

#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

lpuart_dma_shutdown() releases the TX and RX DMA channels but leaves their pointers set. If the device is removed after port shutdown, lpuart_remove() passes the same channels to dma_release_channel() again. This can trigger a DMAengine channel reference count warning.

Clear each channel pointer after releasing it so that lpuart_remove() only releases channels the driver still owns.

Quoted 6 lines

A tool-assisted lifetime review found the extra release. Codex helped draft the fix and this commit message.

Fixes 159381df1442 ("tty: serial: fsl_lpuart: fix DMA operation when using IOMMU")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Yige Jiang
Quoted 10 lines

Subject: [PATCH] tty: serial: fsl_lpuart: avoid releasing DMA channels twice

lpuart_dma_shutdown() releases the TX and RX DMA channels but leaves their pointers set. If the device is removed after port shutdown, lpuart_remove() passes the same channels to dma_release_channel() again. This can trigger a DMAengine channel reference count warning.

Clear each channel pointer after releasing it so that lpuart_remove() only releases channels the driver still owns.

Quoted 7 lines

A tool-assisted lifetime review found the extra release. Codex helped draft the fix and this commit message.

Fixes 159381df1442 ("tty: serial: fsl_lpuart: fix DMA operation when using

IOMMU")

Best Regards
Sherry

Quoted 31 lines

---
Compile-tested on arm64 defconfig with GCC 14.2 and W=1.

 drivers/tty/serial/fsl_lpuart.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/tty/serial/fsl_lpuart.c index renamed from drivers/tty/serial/fsl_lpuart.c +0 -0

e54b4c44db42..17a67805b208 100644

drivers/tty/serial/fsl_lpuart.c +7 -2
@@ -1934,10 +1934,15 @@ static void lpuart_dma_shutdown(struct
 lpuart_port *sport)
 		sport->lpuart_dma_tx_use = false;
 	}
 
-	if (sport->dma_tx_chan)
+	if (sport->dma_tx_chan) {
 		dma_release_channel(sport->dma_tx_chan);
-	if (sport->dma_rx_chan)
+		sport->dma_tx_chan = NULL;
+	}
+
+	if (sport->dma_rx_chan) {
 		dma_release_channel(sport->dma_rx_chan);
+		sport->dma_rx_chan = NULL;
+	}
 }
 

static void lpuart_shutdown(struct uart_port *port)

base-commit: eedf2cf3505c1562a2fb24f8b997056f023d242b