From: Lizhi Hou Date: Mon, 18 Aug 2025 15:22:21 +0000 (-0700) Subject: of: dynamic: Fix memleak when of_pci_add_properties() failed X-Git-Tag: v6.16.5~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28f023beca38adc0093b5cd5d40e9b1b7f3539e3;p=thirdparty%2Fkernel%2Fstable.git of: dynamic: Fix memleak when of_pci_add_properties() failed [ Upstream commit c81f6ce16785cc07ae81f53deb07b662ed0bb3a5 ] 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 Closes: https://lore.kernel.org/all/aJms+YT8TnpzpCY8@lpieralisi/ Tested-by: Lorenzo Pieralisi Signed-off-by: Lizhi Hou Link: https://lore.kernel.org/r/20250818152221.3685724-1-lizhi.hou@amd.com Signed-off-by: Rob Herring (Arm) Signed-off-by: Sasha Levin --- diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 0aba760f7577e..dd30b7d8b5e46 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; }