Skip to contentSkip to conversation

of: unittest: fix memory leak in unittest_data_add

PATCH Applied Navid Emamdoost 4 participants 4 messages Oct 4, 2019 – Oct 17, 2019

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

PATCH 1/1 of: unittest: fix memory leak in unittest_data_add

In unittest_data_add, a copy buffer is created via kmemdup. This buffer is leaked if of_fdt_unflatten_tree fails. The release for the unittest_data buffer is added.

Fixes b951f9dc7f25 ("Enabling OF selftest to run without machine's devicetree")
---
 drivers/of/unittest.c | 1 +
 1 file changed, 1 insertion(+)
drivers/of/unittest.c +1 -0
index 480a21e2ed39..92e895d86458 100644
@@ -1207,6 +1207,7 @@ static int __init unittest_data_add(void)
 	of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node);
 	if (!unittest_data_node) {
 		pr_warn("%s: No tree to attach; not running tests\n", __func__);
+		kfree(unittest_data);
 		return -ENODATA;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines

In unittest_data_add, a copy buffer is created via kmemdup. This buffer is leaked if of_fdt_unflatten_tree fails. The release for the unittest_data buffer is added.

Can a wording like the following be nicer for the change description?

The buffer “__dtb_testcases_begin” will be duplicated to the local variable “unittest_data”. Release the corresponding memory after a call of the function “of_fdt_unflatten_tree” failed in the implementation of the function “unittest_data_add”.

Regards,
Markus

maintainer Applied
#2 lore raw
In reply to Navid Emamdoost
Quoted 10 lines · Navid Emamdoost

In unittest_data_add, a copy buffer is created via kmemdup. This buffer is leaked if of_fdt_unflatten_tree fails. The release for the unittest_data buffer is added.

Fixes b951f9dc7f25 ("Enabling OF selftest to run without machine's devicetree")
---
 drivers/of/unittest.c | 1 +
 1 file changed, 1 insertion(+)

Applied, thanks.

Rob

Reviewed-by
#3 lore raw
Quoted 12 lines · Rob Herring
Quoted 10 lines · Navid Emamdoost

In unittest_data_add, a copy buffer is created via kmemdup. This buffer is leaked if of_fdt_unflatten_tree fails. The release for the unittest_data buffer is added.

Fixes b951f9dc7f25 ("Enabling OF selftest to run without machine's devicetree")
---
 drivers/of/unittest.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 4 lines

Applied, thanks.

Rob

Academic since already applied, but: