diff mbox series

sparc: Fix possible memleak in of_set_property

Message ID 20221104122708.15488-1-zhangqilong3@huawei.com
State New
Headers show
Series sparc: Fix possible memleak in of_set_property | expand

Commit Message

Zhang Qilong Nov. 4, 2022, 12:27 p.m. UTC
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.")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 arch/sparc/kernel/prom_common.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index c9ec70888a39..c127a815db5e 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -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;