devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] of: dynamic: Fix memleak when of_pci_add_properties() failed
@ 2025-08-18 15:22 Lizhi Hou
  2025-08-20 23:31 ` Rob Herring (Arm)
  0 siblings, 1 reply; 2+ messages in thread
From: Lizhi Hou @ 2025-08-18 15:22 UTC (permalink / raw)
  To: robh, lpieralisi; +Cc: Lizhi Hou, devicetree, linux-kernel

When of_pci_add_properties() failed, of_changeset_destroy() is called to
free the changeset. And of_changeset_destroy() puts device tree node in
each entry but does not free property in the entry. This leads to memory
leak in the failure case.

In of_changeset_add_prop_helper(), add the property to the device tree node
deadprops list. Thus, the property will also be freed along with device
tree node.

Fixes: b544fc2b8606 ("of: dynamic: Add interfaces for creating device node dynamically")
Reported-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Closes: https://lore.kernel.org/all/aJms+YT8TnpzpCY8@lpieralisi/
Tested-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/of/dynamic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 0aba760f7577..dd30b7d8b5e4 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -938,6 +938,9 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
 	if (ret)
 		__of_prop_free(new_pp);
 
+	new_pp->next = np->deadprops;
+	np->deadprops = new_pp;
+
 	return ret;
 }
 
-- 
2.34.1


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

* Re: [PATCH V2] of: dynamic: Fix memleak when of_pci_add_properties() failed
  2025-08-18 15:22 [PATCH V2] of: dynamic: Fix memleak when of_pci_add_properties() failed Lizhi Hou
@ 2025-08-20 23:31 ` Rob Herring (Arm)
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring (Arm) @ 2025-08-20 23:31 UTC (permalink / raw)
  To: Lizhi Hou; +Cc: lpieralisi, devicetree, linux-kernel


On Mon, 18 Aug 2025 08:22:21 -0700, Lizhi Hou wrote:
> When of_pci_add_properties() failed, of_changeset_destroy() is called to
> free the changeset. And of_changeset_destroy() puts device tree node in
> each entry but does not free property in the entry. This leads to memory
> leak in the failure case.
> 
> In of_changeset_add_prop_helper(), add the property to the device tree node
> deadprops list. Thus, the property will also be freed along with device
> tree node.
> 
> Fixes: b544fc2b8606 ("of: dynamic: Add interfaces for creating device node dynamically")
> Reported-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
> Closes: https://lore.kernel.org/all/aJms+YT8TnpzpCY8@lpieralisi/
> Tested-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> ---
>  drivers/of/dynamic.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

Applied, thanks!


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

end of thread, other threads:[~2025-08-20 23:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 15:22 [PATCH V2] of: dynamic: Fix memleak when of_pci_add_properties() failed Lizhi Hou
2025-08-20 23:31 ` Rob Herring (Arm)

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).