Devicetree
 help / color / mirror / Atom feed
* [PATCH] of: unittest: fix node reference leak in of_unittest_match_node()
@ 2026-11-03 10:42 Wentao Liang
  2026-11-03 11:10 ` Krzysztof Kozlowski
  2026-11-05 15:42 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-03 10:42 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: devicetree, linux-kernel, Wentao Liang, stable

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@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
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 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-05 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 10:42 [PATCH] of: unittest: fix node reference leak in of_unittest_match_node() Wentao Liang
2026-11-03 11:10 ` Krzysztof Kozlowski
2026-11-05 15:42 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox