* [PATCH] tty: serial: pch_uart: add check for dma_alloc_coherent()
@ 2026-04-08 7:24 Zhaoyang Yu
2026-04-08 13:22 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Zhaoyang Yu @ 2026-04-08 7:24 UTC (permalink / raw)
To: gregkh, jirislaby
Cc: andriy.shevchenko, kees, fourier.thomas, linux-serial,
linux-kernel, gszhai, 2426767509
From: Zhaoyang Yu <2426767509@qq.com>
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.
Signed-off-by: Zhaoyang Yu <2426767509@qq.com>
---
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 [flat|nested] 3+ messages in thread* Re: [PATCH] tty: serial: pch_uart: add check for dma_alloc_coherent()
2026-04-08 7:24 [PATCH] tty: serial: pch_uart: add check for dma_alloc_coherent() Zhaoyang Yu
@ 2026-04-08 13:22 ` Andy Shevchenko
2026-04-09 5:46 ` 俞朝阳
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-08 13:22 UTC (permalink / raw)
To: Zhaoyang Yu
Cc: gregkh, jirislaby, kees, fourier.thomas, linux-serial,
linux-kernel, gszhai, 2426767509
On Wed, Apr 08, 2026 at 03:24:21PM +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.
Looks like it deserves a Fixes tag.
Also ideally this driver should be converted to one of 8250 cases.
The latter has already DMA support. Note, if you are going this
direction, I have the hardware to test.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: serial: pch_uart: add check for dma_alloc_coherent()
2026-04-08 13:22 ` Andy Shevchenko
@ 2026-04-09 5:46 ` 俞朝阳
0 siblings, 0 replies; 3+ messages in thread
From: 俞朝阳 @ 2026-04-09 5:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: gregkh, jirislaby, kees, fourier.thomas, linux-serial,
linux-kernel, gszhai, Zhaoyang Yu
Hi Andy,
Thank you for the review and the suggestions!
> Looks like it deserves a Fixes tag.
Agreed. I will find the original commit that introduced this issue and add the proper Fixes tag in the v2 patch. I'll send it out shortly.
> Also ideally this driver should be converted to one of 8250 cases.
> The latter has already DMA support. Note, if you are going this
> direction, I have the hardware to test.
Thank you very much for offering to test on the actual hardware! That is incredibly helpful.
I agree that converting this driver to the 8250 framework is the right direction. Since that would be a larger refactoring effort, I think it might be best to apply this quick NULL pointer fix first so that the current driver is safe.
After this fix is settled, I am very interested in taking a look at the 8250 conversion as a follow-up project. I might need some time to study the 8250 DMA framework, but I will definitely reach out with a patch series for you to test when I get there!
Best regards,
Zhaoyang Yu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-09 5:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-08 7:24 [PATCH] tty: serial: pch_uart: add check for dma_alloc_coherent() Zhaoyang Yu
2026-04-08 13:22 ` Andy Shevchenko
2026-04-09 5:46 ` 俞朝阳
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®