linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_lpss: Fix memory leak in lpss8250_probe()
@ 2024-04-26 13:39 lumingyindetect
  2024-04-26 13:48 ` Ilpo Järvinen
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: lumingyindetect @ 2024-04-26 13:39 UTC (permalink / raw)
  To: linux-kernel, linux-serial
  Cc: ilpo.jarvinen, andriy.shevchenko, gregkh, jirislaby, LuMingYin

From: LuMingYin <lumingyindetect@126.com>

The return statements at line 347 and line 351 in the lpss8250_probe() function result in a memory leak of the variable pdev.
Add a label named free_irq_vectors in the lpss8250_probe() function to release the memory area pointed to by pdev.
Modify the two return statements mentioned above to jump to the label "free_irq_vectors" instead.

Fixes: e88c4cfcb7b888ac374916806f86c17d8ecaeb67 ("serial: 8250_lpss: fix memory in lpss8250_probe()")

Signed-off-by: LuMingYin <lumingyindetect@126.com>
---
 drivers/tty/serial/8250/8250_lpss.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index c3cd6cb9ac80..fa9fd4dc86c7 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -344,11 +344,11 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	uart.port.mapbase = pci_resource_start(pdev, 0);
 	uart.port.membase = pcim_iomap(pdev, 0, 0);
 	if (!uart.port.membase)
-		return -ENOMEM;
+		goto free_irq_vectors;
 
 	ret = lpss->board->setup(lpss, &uart.port);
 	if (ret)
-		return ret;
+		goto free_irq_vectors;
 
 	dw8250_setup_port(&uart.port);
 
@@ -367,6 +367,7 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 err_exit:
 	lpss->board->exit(lpss);
+free_irq_vectors:
 	pci_free_irq_vectors(pdev);
 	return ret;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] serial: 8250_lpss: Fix memory leak in lpss8250_probe()
@ 2024-04-26 11:47 lumingyindetect
  2024-04-26 12:28 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: lumingyindetect @ 2024-04-26 11:47 UTC (permalink / raw)
  To: linux-kernel, linux-serial
  Cc: ilpo.jarvinen, andriy.shevchenko, gregkh, jirislaby, LuMingYin

From: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>

In the execution logic of the lpss8250_probe() function, the function may directly return via a return statement at either line 347 or line 351.
Unlike lines 357 or 361, where the return statement is used directly without releasing the dynamically allocated memory region pointed to by the variable pdev, causing a memory leak of the variable pdev.
In the lpss8250_probe() function, I added a label named "free_irq_vectors" to release the dynamically allocated memory region pointed to by the variable pdev, and replaced the two return statements mentioned above with goto statements to this label.

Fixes: e88c4cfcb7b888ac374916806f86c17d8ecaeb67

Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
---
 drivers/tty/serial/8250/8250_lpss.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index c3cd6cb9ac80..fa9fd4dc86c7 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -344,11 +344,11 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	uart.port.mapbase = pci_resource_start(pdev, 0);
 	uart.port.membase = pcim_iomap(pdev, 0, 0);
 	if (!uart.port.membase)
-		return -ENOMEM;
+		goto free_irq_vectors;
 
 	ret = lpss->board->setup(lpss, &uart.port);
 	if (ret)
-		return ret;
+		goto free_irq_vectors;
 
 	dw8250_setup_port(&uart.port);
 
@@ -367,6 +367,7 @@ static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 err_exit:
 	lpss->board->exit(lpss);
+free_irq_vectors:
 	pci_free_irq_vectors(pdev);
 	return ret;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-04-26 15:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 13:39 [PATCH] serial: 8250_lpss: Fix memory leak in lpss8250_probe() lumingyindetect
2024-04-26 13:48 ` Ilpo Järvinen
2024-04-26 13:55 ` Greg KH
2024-04-26 14:44 ` Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2024-04-26 11:47 lumingyindetect
2024-04-26 12:28 ` Markus Elfring
2024-04-26 13:01   ` lumingyindetect
2024-04-26 15:07     ` Christian Heusel
2024-04-26 13:45 ` Ilpo Järvinen
2024-04-26 13:53 ` Dan Carpenter
2024-04-26 14:45   ` Andy Shevchenko
2024-04-26 15:32     ` Dan Carpenter
2024-04-26 15:37       ` Andy Shevchenko

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).