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

From: Wentao Liang

Date: Thu Sep 17 2026 - 10:06:53 EST


Every iteration takes a reference with of_find_node_by_path() but the
loop never drops it, neither on the early continue paths nor after a
successful match. Add the missing of_node_put() calls.

Fixes: 1f42e5dd5065 ("of: Add self test for of_match_node()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/of/unittest.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 316f082c430d..900840850814 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1897,6 +1897,7 @@ static void __init of_unittest_match_node(void)
if (!match) {
unittest(0, "%s didn't match anything\n",
match_node_tests[i].path);
+ of_node_put(np);
continue;
}

@@ -1904,9 +1905,11 @@ static void __init of_unittest_match_node(void)
unittest(0, "%s got wrong match. expected %s, got %s\n",
match_node_tests[i].path, match_node_tests[i].data,
(const char *)match->data);
+ of_node_put(np);
continue;
}
unittest(1, "passed");
+ of_node_put(np);
}
}

--
2.34.1