From: Bjorn Helgaas <helgaas@kernel.org>
To: Lizhi Hou <lizhi.hou@amd.com>
Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, herve.codina@bootlin.com,
Jonathan.Cameron@huawei.com, bhelgaas@google.com,
robh@kernel.org
Subject: Re: [PATCH v3] PCI: of: Fix memory leak when of_changeset_create_node() failed
Date: Fri, 29 Sep 2023 17:37:18 -0500 [thread overview]
Message-ID: <20230929223718.GA558826@bhelgaas> (raw)
In-Reply-To: <1696007417-42059-1-git-send-email-lizhi.hou@amd.com>
On Fri, Sep 29, 2023 at 10:10:17AM -0700, Lizhi Hou wrote:
> In function of_pci_make_dev_node(), the cset needs to be destroyed and
> freed when of_changeset_create_node() returns null.
>
> 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>
Applied with Herve's Reviewed-by to for-linus for v6.6, since
407d1a51921e appeared in v6.6-rc1, thanks!
> ---
> 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..51e3dd0ea5ab 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 out_free_name;
> of_changeset_init(cset);
>
> np = of_changeset_create_node(cset, ppnode, name);
> if (!np)
> - goto failed;
> - np->data = cset;
> + goto out_destroy_cset;
>
> ret = of_pci_add_properties(pdev, cset, np);
> if (ret)
> - goto failed;
> + goto out_free_node;
>
> ret = of_changeset_apply(cset);
> if (ret)
> - goto failed;
> + goto out_free_node;
>
> + np->data = cset;
> pdev->dev.of_node = np;
> kfree(name);
>
> return;
>
> -failed:
> - if (np)
> - of_node_put(np);
> +out_free_node:
> + of_node_put(np);
> +out_destroy_cset:
> + of_changeset_destroy(cset);
> + kfree(cset);
> +out_free_name:
> kfree(name);
> }
> #endif
> --
> 2.34.1
>
prev parent reply other threads:[~2023-09-29 22:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 17:10 [PATCH v3] PCI: of: Fix memory leak when of_changeset_create_node() failed Lizhi Hou
2023-09-29 17:18 ` Herve Codina
2023-09-29 22:37 ` Bjorn Helgaas [this message]
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=20230929223718.GA558826@bhelgaas \
--to=helgaas@kernel.org \
--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=lizhi.hou@amd.com \
--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).