From: Chunyan Zhang <chunyan.zhang@unisoc.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: <linux-serial@vger.kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Orson Zhai <orsonzhai@gmail.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Chunyan Zhang <chunyan.zhang@unisoc.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH V3 2/2] serial: sprd: Fix DMA buffer leak issue
Date: Tue, 25 Jul 2023 14:40:53 +0800 [thread overview]
Message-ID: <20230725064053.235448-2-chunyan.zhang@unisoc.com> (raw)
In-Reply-To: <20230725064053.235448-1-chunyan.zhang@unisoc.com>
Release DMA buffer when _probe() returns failure to avoid memory leak.
Fixes: f4487db58eb7 ("serial: sprd: Add DMA mode support")
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
V3:
- Corresponding changes based on patch-1.
V2:
- Added Baolin's Reviewed-by;
- Add setting rx_dma.virt to NULL after being freed.
---
drivers/tty/serial/sprd_serial.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index fc1377029021..99da964e8bd4 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -364,7 +364,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)
@@ -1203,7 +1203,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;
}
}
@@ -1222,6 +1222,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;
}
--
2.41.0
next prev parent reply other threads:[~2023-07-25 6:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 6:40 [PATCH V3 1/2] serial: sprd: Assign sprd_port after initialized to avoid wrong access Chunyan Zhang
2023-07-25 6:40 ` Chunyan Zhang [this message]
2023-07-25 6:50 ` Greg Kroah-Hartman
2023-07-25 7:49 ` Chunyan Zhang
2023-07-25 17:33 ` Greg Kroah-Hartman
2023-07-31 3:55 ` Baolin Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230725064053.235448-2-chunyan.zhang@unisoc.com \
--to=chunyan.zhang@unisoc.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=zhang.lyra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox