[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240426114716.1275085-1-lumingyindetect@126.com>
Date: Fri, 26 Apr 2024 12:47:16 +0100
From: lumingyindetect@....com
To: linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org
Cc: ilpo.jarvinen@...ux.intel.com,
andriy.shevchenko@...ux.intel.com,
gregkh@...uxfoundation.org,
jirislaby@...nel.org,
LuMingYin <11570291+yin-luming@...r.noreply.gitee.com>
Subject: [PATCH] serial: 8250_lpss: Fix memory leak in lpss8250_probe()
From: LuMingYin <11570291+yin-luming@...r.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@...r.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
Powered by blists - more mailing lists