* [PATCH] Fix a memory leak in the function lpss8250_probe
@ 2024-04-26 10:45 lumingyindetect
2024-04-26 10:51 ` Ilpo Järvinen
0 siblings, 1 reply; 2+ messages in thread
From: lumingyindetect @ 2024-04-26 10:45 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 lpss8250_probe function in the 8250_lpss.c file, the program may directly return at either line 347 or line 351, without jumping to the error handling label to release the dynamically allocated memory region pointed to by the variable pdev, as done at line 357 or line 361. This fix introduces a new label named free_irq_vectors to release the dynamically allocated memory region pointed to by pdev, thereby fixing the memory leak defect.
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] 2+ messages in thread
* Re: [PATCH] Fix a memory leak in the function lpss8250_probe
2024-04-26 10:45 [PATCH] Fix a memory leak in the function lpss8250_probe lumingyindetect
@ 2024-04-26 10:51 ` Ilpo Järvinen
0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2024-04-26 10:51 UTC (permalink / raw)
To: lumingyindetect
Cc: LKML, linux-serial, Andy Shevchenko, Greg Kroah-Hartman,
Jiri Slaby, LuMingYin
On Fri, 26 Apr 2024, lumingyindetect@126.com wrote:
> From: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
>
> In the lpss8250_probe function in the 8250_lpss.c file, the program may directly return at either line 347 or line 351, without jumping to the error handling label to release the dynamically allocated memory region pointed to by the variable pdev, as done at line 357 or line 361. This fix introduces a new label named free_irq_vectors to release the dynamically allocated memory region pointed to by pdev, thereby fixing the memory leak defect.
Hi,
You left most of my comments unaddressed. :-( Please don't send a new
version unless you've addressed all the comments.
> Signed-off-by: LuMingYin <11570291+yin-luming@user.noreply.gitee.com>
> ---
You also need to name version of the patch on subject line and provide the
version history here underneath --- line.
> 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;
> }
>
--
i.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-26 10:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 10:45 [PATCH] Fix a memory leak in the function lpss8250_probe lumingyindetect
2024-04-26 10:51 ` Ilpo Järvinen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.