[PATCH] PCI: endpoint: functions/pci-epf-test: fix a potential memory leak

xkernel.wang@foxmail.com posted 1 patch 4 years, 4 months ago
drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] PCI: endpoint: functions/pci-epf-test: fix a potential memory leak
Posted by xkernel.wang@foxmail.com 4 years, 4 months ago
From: Xiaoke Wang <xkernel.wang@foxmail.com>

In pci_epf_test_write(), there is an error path does not properly
release 'buf' which is allocated by kzalloc(). It is better to release
it by changing the target label of goto statement.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 90d84d3..41227dd 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -441,7 +441,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
 		if (!epf_test->dma_supported) {
 			dev_err(dev, "Cannot transfer data using DMA\n");
 			ret = -EINVAL;
-			goto err_map_addr;
+			goto err_dma_map;
 		}
 
 		src_phys_addr = dma_map_single(dma_dev, buf, reg->size,
-- 
Re: [EXT] [PATCH] PCI: endpoint: functions/pci-epf-test: fix a potential memory leak
Posted by Li Chen 4 years, 4 months ago
Hi Xiaoke,
This is duplicate  to https://lore.kernel.org/lkml/17ed816b6f3.d4fb44fb69745.1048447841721382920@zohomail.com/T/

Regards,
Li

 ---- On Fri, 18 Feb 2022 00:31:24 +0800  <xkernel.wang@foxmail.com> wrote ----
 > From: Xiaoke Wang <xkernel.wang@foxmail.com>
 > 
 > In pci_epf_test_write(), there is an error path does not properly
 > release 'buf' which is allocated by kzalloc(). It is better to release
 > it by changing the target label of goto statement.
 > 
 > Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
 > ---
 >  drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 >  1 file changed, 1 insertion(+), 1 deletion(-)
 > 
 > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
 > index 90d84d3..41227dd 100644
 > --- a/drivers/pci/endpoint/functions/pci-epf-test.c
 > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
 > @@ -441,7 +441,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
 >          if (!epf_test->dma_supported) {
 >              dev_err(dev, "Cannot transfer data using DMA\n");
 >              ret = -EINVAL;
 > -            goto err_map_addr;
 > +            goto err_dma_map;
 >          }
 >  
 >          src_phys_addr = dma_map_single(dma_dev, buf, reg->size,
 > -- 
 > 
 > ######################################################################
 > This EXTERNAL email has been scanned by Proofpoint Email Protect service.
 > 
Re: [EXT] [PATCH] PCI: endpoint: functions/pci-epf-test: fix a potential memory leak
Posted by Xiaoke Wang 4 years, 4 months ago
---- On Fri, 18 Feb 2022 11:03:02 +0800  Li Chen <lchen.firstlove@zohomail.com> wrote ----
> This is duplicate  to https://lore.kernel.org/lkml/17ed816b6f3.d4fb44fb69745.1048447841721382920@zohomail.com/T/

Oh! I am sorry that I only viewed the code in torvalds/linux git 
repository, but not the mail list.
Thank you for your reminder.

Regards,
Wang