* [PATCH v2] tty: serial: pch_uart: add check for dma_alloc_coherent()
@ 2026-04-09 5:41 Zhaoyang Yu
2026-04-14 17:13 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Zhaoyang Yu @ 2026-04-09 5:41 UTC (permalink / raw)
To: andriy.shevchenko
Cc: gregkh, jirislaby, kees, fourier.thomas, linux-serial,
linux-kernel, gszhai, 23120469, Zhaoyang Yu, stable
Add a check for dma_alloc_coherent() failure to prevent a potential
NULL pointer dereference in dma_handle_rx(). Properly release DMA
channels and the PCI device reference using a goto ladder if the
allocation fails.
Fixes: 3c6a483275f4 ("Serial: EG20T: add PCH_UART driver")
Cc: stable@vger.kernel.org
Signed-off-by: Zhaoyang Yu <2426767509@qq.com>
---
Changes in v2:
- Added the Fixes tag for the initial PCH_UART driver commit, per Andy's review.
drivers/tty/serial/pch_uart.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 6729d8e83c3c..ba1fcd663fe2 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -689,8 +689,7 @@ static void pch_request_dma(struct uart_port *port)
if (!chan) {
dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
__func__);
- pci_dev_put(dma_dev);
- return;
+ goto err_pci_get;
}
priv->chan_tx = chan;
@@ -704,18 +703,26 @@ static void pch_request_dma(struct uart_port *port)
if (!chan) {
dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
__func__);
- dma_release_channel(priv->chan_tx);
- priv->chan_tx = NULL;
- pci_dev_put(dma_dev);
- return;
+ goto err_req_tx;
}
/* 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)
+ goto err_req_rx;
priv->chan_rx = chan;
pci_dev_put(dma_dev);
+ return;
+
+err_req_rx:
+ dma_release_channel(chan);
+err_req_tx:
+ dma_release_channel(priv->chan_tx);
+ priv->chan_tx = NULL;
+err_pci_get:
+ pci_dev_put(dma_dev);
}
static void pch_dma_rx_complete(void *arg)
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tty: serial: pch_uart: add check for dma_alloc_coherent()
2026-04-09 5:41 [PATCH v2] tty: serial: pch_uart: add check for dma_alloc_coherent() Zhaoyang Yu
@ 2026-04-14 17:13 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-04-14 17:13 UTC (permalink / raw)
To: Zhaoyang Yu
Cc: gregkh, jirislaby, kees, fourier.thomas, linux-serial,
linux-kernel, gszhai, 23120469, stable
On Thu, Apr 09, 2026 at 01:41:58PM +0800, Zhaoyang Yu wrote:
> Add a check for dma_alloc_coherent() failure to prevent a potential
> NULL pointer dereference in dma_handle_rx(). Properly release DMA
> channels and the PCI device reference using a goto ladder if the
> allocation fails.
As a fix for backporting it's good enough, ideally should be converted to one
from 8250 family as it was done, for example, for Intel MID (see a history of
8250_mid.c for the details).
FWIW, the HW one may test this on is Intel Minnowboard v1 which uses EG20T PCH.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-14 17:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 5:41 [PATCH v2] tty: serial: pch_uart: add check for dma_alloc_coherent() Zhaoyang Yu
2026-04-14 17:13 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox