[PATCH] of: unittest: Fix np reference leak in of_unittest_parse_phandle_with_args_map()

Wentao Liang posted 1 patch 1 week ago
drivers/of/unittest.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] of: unittest: Fix np reference leak in of_unittest_parse_phandle_with_args_map()
Posted by Wentao Liang 1 week ago
of_find_node_by_path() returns a node with an elevated reference count,
but the function returns without dropping it both when a provider node
is missing and after the last check. Add the missing of_node_put() calls.

Fixes: 357aa4b61c82 ("of: unittest: Add phandle remapping test")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/of/unittest.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 36c64d485a53..e10fff3f68c4 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -581,6 +581,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
 	for (i = 0; i < ARRAY_SIZE(p); ++i) {
 		if (!p[i]) {
 			pr_err("missing testcase data\n");
+			of_node_put(np);
 			return;
 		}
 		prefs[i] = OF_KREF_READ(p[i]);
@@ -711,6 +712,8 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
 			 i, prefs[i], OF_KREF_READ(p[i]));
 		of_node_put(p[i]);
 	}
+
+	of_node_put(np);
 }
 
 static void __init of_unittest_property_string(void)
-- 
2.34.1