devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: <linux-pci@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <herve.codina@bootlin.com>,
	<Jonathan.Cameron@Huawei.com>
Cc: Lizhi Hou <lizhi.hou@amd.com>, <bhelgaas@google.com>, <robh@kernel.org>
Subject: [PATCH 1/2] PCI: of: Fix memory leak when of_changeset_create_node() failed
Date: Fri, 15 Sep 2023 11:08:06 -0700	[thread overview]
Message-ID: <1694801287-17217-1-git-send-email-lizhi.hou@amd.com> (raw)

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


             reply	other threads:[~2023-09-15 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 18:08 Lizhi Hou [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1694801287-17217-1-git-send-email-lizhi.hou@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=herve.codina@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).