[PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Destroy and free cset when failure happens.

Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Reported-by: Herve Codina <herve.codina@xxxxxxxxxxx>
Closes: https://lore.kernel.org/all/20230911171319.495bb837@xxxxxxxxxxx/
Signed-off-by: Lizhi Hou <lizhi.hou@xxxxxxx>
---
 drivers/pci/of.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 2af64bcb7da3..67bbfa2fca59 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -663,7 +663,6 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 	np = of_changeset_create_node(cset, ppnode, name);
 	if (!np)
 		goto failed;
-	np->data = cset;
 
 	ret = of_pci_add_properties(pdev, cset, np);
 	if (ret)
@@ -673,12 +672,17 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 	if (ret)
 		goto failed;
 
+	np->data = cset;
 	pdev->dev.of_node = np;
 	kfree(name);
 
 	return;
 
 failed:
+	if (cset) {
+		of_changeset_destroy(cset);
+		kfree(cset);
+	}
 	if (np)
 		of_node_put(np);
 	kfree(name);
-- 
2.34.1




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux