Skip to contentSkip to conversation

sparc: Fix possible memleak in of_set_property

PATCH New Zhang Qilong 1 participant 1 message Nov 4, 2022 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: Fix possible memleak in of_set_property

If we do not find the target property, this part of memory that allocated to new_val is not referenced by anyone. It can not be freed after of_set_property() returns, then it will be leaked. We fix the problem by freeing it when not found the target name of the property.

Fixes dfa76060be85 ("sparc: Create common area for OF device layer code.")
---
 arch/sparc/kernel/prom_common.c | 3 +++
 1 file changed, 3 insertions(+)
arch/sparc/kernel/prom_common.c +3 -0
index c9ec70888a39..c127a815db5e 100644
@@ -91,6 +91,9 @@ int of_set_property(struct device_node *dp, const char *name, void *val, int len
 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
 	mutex_unlock(&of_set_property_mutex);
 
+	if (err)
+		kfree(new_val);
+
 	/* XXX Upate procfs if necessary... */
 
 	return err;
Signature · 1 line
2.25.1