* [PATCH] serial: amba-pl011: prefer dma_mapping_error() over explicit address checking
@ 2025-10-27 9:20 Miaoqian Lin
2025-10-27 15:04 ` Gregory CLEMENT
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2025-10-27 9:20 UTC (permalink / raw)
To: Russell King, Greg Kroah-Hartman, Jiri Slaby, Thomas Gleixner,
Ingo Molnar, Arnd Bergmann, Nam Cao, Toshiyuki Sato,
Miroslav Ondra, Gregory CLEMENT, linux-kernel, linux-serial
Cc: linmq006, stable
Check for returned DMA addresses using specialized dma_mapping_error()
helper which is generally recommended for this purpose by
Documentation/core-api/dma-api.rst:
"In some circumstances dma_map_single(), ...
will fail to create a mapping. A driver can check for these errors
by testing the returned DMA address with dma_mapping_error()."
Found via static analysis and this is similar to commit fa0308134d26
("ALSA: memalloc: prefer dma_mapping_error() over explicit address checking")
Fixes: 58ac1b379979 ("ARM: PL011: Fix DMA support")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/tty/serial/amba-pl011.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 22939841b1de..7f17d288c807 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -628,7 +628,7 @@ static int pl011_dma_tx_refill(struct uart_amba_port *uap)
dmatx->len = count;
dmatx->dma = dma_map_single(dma_dev->dev, dmatx->buf, count,
DMA_TO_DEVICE);
- if (dmatx->dma == DMA_MAPPING_ERROR) {
+ if (dma_mapping_error(dma_dev->dev, dmatx->dma)) {
uap->dmatx.queued = false;
dev_dbg(uap->port.dev, "unable to map TX DMA\n");
return -EBUSY;
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] serial: amba-pl011: prefer dma_mapping_error() over explicit address checking
2025-10-27 9:20 [PATCH] serial: amba-pl011: prefer dma_mapping_error() over explicit address checking Miaoqian Lin
@ 2025-10-27 15:04 ` Gregory CLEMENT
0 siblings, 0 replies; 2+ messages in thread
From: Gregory CLEMENT @ 2025-10-27 15:04 UTC (permalink / raw)
To: Miaoqian Lin, Russell King, Greg Kroah-Hartman, Jiri Slaby,
Thomas Gleixner, Ingo Molnar, Arnd Bergmann, Nam Cao,
Toshiyuki Sato, Miroslav Ondra, linux-kernel, linux-serial
Cc: linmq006, stable
Miaoqian Lin <linmq006@gmail.com> writes:
> Check for returned DMA addresses using specialized dma_mapping_error()
> helper which is generally recommended for this purpose by
> Documentation/core-api/dma-api.rst:
>
> "In some circumstances dma_map_single(), ...
> will fail to create a mapping. A driver can check for these errors
> by testing the returned DMA address with dma_mapping_error()."
>
> Found via static analysis and this is similar to commit fa0308134d26
> ("ALSA: memalloc: prefer dma_mapping_error() over explicit address checking")
>
> Fixes: 58ac1b379979 ("ARM: PL011: Fix DMA support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Thanks,
Gregory
> ---
> drivers/tty/serial/amba-pl011.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
> index 22939841b1de..7f17d288c807 100644
> --- a/drivers/tty/serial/amba-pl011.c
> +++ b/drivers/tty/serial/amba-pl011.c
> @@ -628,7 +628,7 @@ static int pl011_dma_tx_refill(struct uart_amba_port *uap)
> dmatx->len = count;
> dmatx->dma = dma_map_single(dma_dev->dev, dmatx->buf, count,
> DMA_TO_DEVICE);
> - if (dmatx->dma == DMA_MAPPING_ERROR) {
> + if (dma_mapping_error(dma_dev->dev, dmatx->dma)) {
> uap->dmatx.queued = false;
> dev_dbg(uap->port.dev, "unable to map TX DMA\n");
> return -EBUSY;
> --
> 2.39.5 (Apple Git-154)
>
--
Grégory CLEMENT, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-27 15:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 9:20 [PATCH] serial: amba-pl011: prefer dma_mapping_error() over explicit address checking Miaoqian Lin
2025-10-27 15:04 ` Gregory CLEMENT
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).