* [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed
@ 2023-09-14 18:15 Lizhi Hou
2023-09-15 7:04 ` Herve Codina
2023-09-15 16:20 ` Rob Herring
0 siblings, 2 replies; 5+ messages in thread
From: Lizhi Hou @ 2023-09-14 18:15 UTC (permalink / raw)
To: linux-pci, devicetree, linux-kernel, herve.codina
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 | 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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed
2023-09-14 18:15 [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed Lizhi Hou
@ 2023-09-15 7:04 ` Herve Codina
2023-09-15 15:25 ` Lizhi Hou
2023-09-15 16:20 ` Rob Herring
1 sibling, 1 reply; 5+ messages in thread
From: Herve Codina @ 2023-09-15 7:04 UTC (permalink / raw)
To: Lizhi Hou; +Cc: linux-pci, devicetree, linux-kernel, bhelgaas, robh
Hi Lizhi
On Thu, 14 Sep 2023 11:15:51 -0700
Lizhi Hou <lizhi.hou@amd.com> wrote:
> 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 | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 2af64bcb7da3..67bbfa2fca59 100644
Why this patch alone ?
The issue fixed by this patch is related to the patch 2 in a series under review
https://lore.kernel.org/linux-kernel/ZQGaSr+G5qu%2F8nJZ@smile.fi.intel.com/
Is the patch 2 in this series already applied by some maintainers ?
You have to fix the patch in the series sending a new iteration of the series.
This patch alone does not make sense.
Otherwise, the modifications to fix the issue seem good.
Regards,
Hervé
> --- 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);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed
2023-09-15 7:04 ` Herve Codina
@ 2023-09-15 15:25 ` Lizhi Hou
0 siblings, 0 replies; 5+ messages in thread
From: Lizhi Hou @ 2023-09-15 15:25 UTC (permalink / raw)
To: Herve Codina; +Cc: linux-pci, devicetree, linux-kernel, bhelgaas, robh
On 9/15/23 00:04, Herve Codina wrote:
> Hi Lizhi
>
> On Thu, 14 Sep 2023 11:15:51 -0700
> Lizhi Hou <lizhi.hou@amd.com> wrote:
>
>> 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 | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
>> index 2af64bcb7da3..67bbfa2fca59 100644
> Why this patch alone ?
> The issue fixed by this patch is related to the patch 2 in a series under review
> https://lore.kernel.org/linux-kernel/ZQGaSr+G5qu%2F8nJZ@smile.fi.intel.com/
> Is the patch 2 in this series already applied by some maintainers ?
Yes.
>
> You have to fix the patch in the series sending a new iteration of the series.
>
> This patch alone does not make sense.
>
> Otherwise, the modifications to fix the issue seem good.
>
> Regards,
> Hervé
>
>> --- 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);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed
2023-09-14 18:15 [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed Lizhi Hou
2023-09-15 7:04 ` Herve Codina
@ 2023-09-15 16:20 ` Rob Herring
2023-09-15 17:11 ` Lizhi Hou
1 sibling, 1 reply; 5+ messages in thread
From: Rob Herring @ 2023-09-15 16:20 UTC (permalink / raw)
To: Lizhi Hou; +Cc: linux-pci, devicetree, linux-kernel, herve.codina, bhelgaas
On Thu, Sep 14, 2023 at 1:16 PM Lizhi Hou <lizhi.hou@amd.com> wrote:
>
> 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 | 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) {
Instead of adding more if's, use multiple goto labels which is the
normal cleanup style. Note that there's a new cleanup.h thing that can
do some automatic cleanups. Not sure if that works or helps here.
> + of_changeset_destroy(cset);
> + kfree(cset);
> + }
> if (np)
> of_node_put(np);
> kfree(name);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed
2023-09-15 16:20 ` Rob Herring
@ 2023-09-15 17:11 ` Lizhi Hou
0 siblings, 0 replies; 5+ messages in thread
From: Lizhi Hou @ 2023-09-15 17:11 UTC (permalink / raw)
To: Rob Herring; +Cc: linux-pci, devicetree, linux-kernel, herve.codina, bhelgaas
On 9/15/23 09:20, Rob Herring wrote:
> On Thu, Sep 14, 2023 at 1:16 PM Lizhi Hou <lizhi.hou@amd.com> wrote:
>> 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 | 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) {
> Instead of adding more if's, use multiple goto labels which is the
> normal cleanup style. Note that there's a new cleanup.h thing that can
> do some automatic cleanups. Not sure if that works or helps here.
Ok. I will create another patch to use multiple goto labels.
Lizhi
>
>> + of_changeset_destroy(cset);
>> + kfree(cset);
>> + }
>> if (np)
>> of_node_put(np);
>> kfree(name);
>> --
>> 2.34.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-15 17:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 18:15 [PATCH] PCI: of: Fix memory leak when of_changeset_create_node() failed Lizhi Hou
2023-09-15 7:04 ` Herve Codina
2023-09-15 15:25 ` Lizhi Hou
2023-09-15 16:20 ` Rob Herring
2023-09-15 17:11 ` Lizhi Hou
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).