of: dynamic: Fix memleak when of_pci_add_properties() failed

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: b544fc2b86 ("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>
This commit is contained in:
Lizhi Hou 2025-08-18 08:22:21 -07:00 committed by Rob Herring (Arm)
parent 79aef1a370
commit c81f6ce167

View File

@ -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;
}