[PATCH] of: unittest: fix node reference leak in of_unittest_match_node()

From: Wentao Liang

Date: Tue Nov 03 2026 - 07:17:11 EST


of_find_node_by_path() returns a device_node with its reference count
incremented. of_unittest_match_node() never releases that reference:
failed matches continue to the next iteration, and the reference taken
for the last test case is still held when the function returns.

Drop the reference on all three paths.

Fixes: 1f42e5dd5065 ("of: Add self test for of_match_node()")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
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 e255f54f4d76..7426d13e9958 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1921,6 +1921,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;
}

@@ -1928,9 +1929,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