Skip to content

Commit

Permalink
serial: sprd: Fix DMA buffer leak issue
Browse files Browse the repository at this point in the history
[ Upstream commit cd119fd ]

Release DMA buffer when _probe() returns failure to avoid memory leak.

Fixes: f4487db ("serial: sprd: Add DMA mode support")
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230725064053.235448-2-chunyan.zhang@unisoc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Chunyan Zhang authored and gregkh committed Sep 13, 2023
1 parent 70f7513 commit 6d209ed
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/tty/serial/sprd_serial.c
Expand Up @@ -367,7 +367,7 @@ static void sprd_rx_free_buf(struct sprd_uart_port *sp)
if (sp->rx_dma.virt)
dma_free_coherent(sp->port.dev, SPRD_UART_RX_SIZE,
sp->rx_dma.virt, sp->rx_dma.phys_addr);

sp->rx_dma.virt = NULL;
}

static int sprd_rx_dma_config(struct uart_port *port, u32 burst)
Expand Down Expand Up @@ -1229,7 +1229,7 @@ static int sprd_probe(struct platform_device *pdev)
ret = uart_register_driver(&sprd_uart_driver);
if (ret < 0) {
pr_err("Failed to register SPRD-UART driver\n");
return ret;
goto free_rx_buf;
}
}

Expand All @@ -1248,6 +1248,7 @@ static int sprd_probe(struct platform_device *pdev)
sprd_port[index] = NULL;
if (--sprd_ports_num == 0)
uart_unregister_driver(&sprd_uart_driver);
free_rx_buf:
sprd_rx_free_buf(sport);
return ret;
}
Expand Down

0 comments on commit 6d209ed

Please sign in to comment.