Skip to content

Commit 28f023b

Browse files
houlz0507gregkh
authored andcommitted
of: dynamic: Fix memleak when of_pci_add_properties() failed
[ Upstream commit c81f6ce ] 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: b544fc2 ("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> Link: https://lore.kernel.org/r/20250818152221.3685724-1-lizhi.hou@amd.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 000aa47 commit 28f023b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/of/dynamic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
938938
if (ret)
939939
__of_prop_free(new_pp);
940940

941+
new_pp->next = np->deadprops;
942+
np->deadprops = new_pp;
943+
941944
return ret;
942945
}
943946

0 commit comments

Comments
 (0)