Thread (2 messages) 2 messages, 2 authors, 2021-12-16
STALE1679d

[PATCH v2] serial: pch_uart: potential dereference of null pointer

From: Jiasheng Jiang <hidden>
Date: 2021-12-16 12:51:46
Also in: lkml
Subsystem: the rest, tty layer and serial drivers · Maintainers: Linus Torvalds, Greg Kroah-Hartman, Jiri Slaby

The return value of dma_alloc_coherent() needs to be checked.
To avoid dereference of null pointer in case of the failure of alloc.

Fixes: ab4382d27412 ("tty: move drivers/serial/ to drivers/tty/serial/")
Signed-off-by: Jiasheng Jiang <redacted>
---
Changelog:

v1 -> v2

*Change 1. Add the dev_err when dma_alloc_coherent failed.
---
 drivers/tty/serial/pch_uart.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index f0351e6f0ef6..d19ed7da24fa 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -745,6 +745,14 @@ static void pch_request_dma(struct uart_port *port)
 	/* Get Consistent memory for DMA */
 	priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
 				    &priv->rx_buf_dma, GFP_KERNEL);
+	if (!priv->rx_buf_virt) {
+		dev_err(priv->port.dev, "%s:dma_alloc_coherent FAILS(Rx)\n",
+			__func__);
+		dma_release_channel(priv->chan_tx);
+		priv->chan_tx = NULL;
+		return;
+	}
+
 	priv->chan_rx = chan;
 }
 
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help