devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed
@ 2023-09-15 18:08 Lizhi Hou
  2023-09-15 18:08 ` [PATCH 2/2] PCI: of_property: Fix uninitialized variable when of_irq_parse_raw() failed Lizhi Hou
  2023-09-28  7:26 ` [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Herve Codina
  0 siblings, 2 replies; 4+ messages in thread
From: Lizhi Hou @ 2023-09-15 18:08 UTC (permalink / raw)
  To: linux-pci, devicetree, linux-kernel, herve.codina,
	Jonathan.Cameron
  Cc: Lizhi Hou, bhelgaas, robh

Destroy and free cset when failure happens.

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

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 2af64bcb7da3..498b5cae8bca 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -657,30 +657,33 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 
 	cset = kmalloc(sizeof(*cset), GFP_KERNEL);
 	if (!cset)
-		goto failed;
+		goto failed_alloc_cset;
 	of_changeset_init(cset);
 
 	np = of_changeset_create_node(cset, ppnode, name);
 	if (!np)
-		goto failed;
-	np->data = cset;
+		goto failed_create_node;
 
 	ret = of_pci_add_properties(pdev, cset, np);
 	if (ret)
-		goto failed;
+		goto failed_add_prop;
 
 	ret = of_changeset_apply(cset);
 	if (ret)
-		goto failed;
+		goto failed_add_prop;
 
+	np->data = cset;
 	pdev->dev.of_node = np;
 	kfree(name);
 
 	return;
 
-failed:
-	if (np)
-		of_node_put(np);
+failed_add_prop:
+	of_node_put(np);
+failed_create_node:
+	of_changeset_destroy(cset);
+	kfree(cset);
+failed_alloc_cset:
 	kfree(name);
 }
 #endif
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-28  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 18:08 [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Lizhi Hou
2023-09-15 18:08 ` [PATCH 2/2] PCI: of_property: Fix uninitialized variable when of_irq_parse_raw() failed Lizhi Hou
2023-09-28  7:29   ` Herve Codina
2023-09-28  7:26 ` [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed Herve Codina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).