Skip to contentSkip to conversation

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

PATCH In review [email protected] 2 participants 3 messages Feb 17, 2022 – Feb 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

From: Xiaoke Wang <[email protected]>

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.

---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -1
index 90d84d3..41227dd 100644
@@ -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,
#1 lore raw

Hi Xiaoke,
This is duplicate to https://lore.kernel.org/lkml/[email protected]/T/

Regards,
Li

---- On Fri, 18 Feb 2022 00:31:24 +0800 <[email protected]> wrote ----

Quoted 29 lines

From: Xiaoke Wang <[email protected]>

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.

---
 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -1
index 90d84d3..41227dd 100644
@@ -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,
Signature · 2 lines
######################################################################
This EXTERNAL email has been scanned by Proofpoint Email Protect service.