Skip to contentSkip to conversation

of: dynamic: Fix use after free in of_changeset_add_prop_helper()

PATCH Applied Dan Carpenter 2 participants 2 messages Aug 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: dynamic: Fix use after free in of_changeset_add_prop_helper()

If the of_changeset_add_property() function call fails, then this code frees "new_pp" and then dereference it on the next line. Return the error code directly instead.

Fixes c81f6ce16785 ("of: dynamic: Fix memleak when of_pci_add_properties() failed")
---
 drivers/of/dynamic.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/of/dynamic.c +4 -2
index dd30b7d8b5e4..2eaaddcb0ec4 100644
@@ -935,13 +935,15 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
 		return -ENOMEM;
 
 	ret = of_changeset_add_property(ocs, np, new_pp);
-	if (ret)
+	if (ret) {
 		__of_prop_free(new_pp);
+		return ret;
+	}
 
 	new_pp->next = np->deadprops;
 	np->deadprops = new_pp;
 
-	return ret;
+	return 0;
 }
 
 /**
Signature · 1 line
2.47.2
maintainer Applied
#1 lore raw
Quoted 10 lines · Dan Carpenter

If the of_changeset_add_property() function call fails, then this code frees "new_pp" and then dereference it on the next line. Return the error code directly instead.

Fixes c81f6ce16785 ("of: dynamic: Fix memleak when of_pci_add_properties() failed")
---
 drivers/of/dynamic.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks!