[PATCH] of: unittest: Fix np reference leaks in of_unittest_platform_populate()
From: Wentao Liang
Date: Thu Sep 17 2026 - 10:20:45 EST
np holds a reference obtained from of_find_node_by_path() but is
reassigned several times without a matching of_node_put(). Drop the
reference before each reassignment so it is not leaked on any path
through the function.
Fixes: 82c0f5897a87 ("of: selftest: add deferred probe interrupt test")
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 6bc5babddf0a..4a8af9b992c4 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1934,6 +1934,7 @@ static void __init of_unittest_platform_populate(void)
np = of_find_node_by_path("/testcase-data");
of_platform_default_populate(np, NULL, NULL);
+ of_node_put(np);
/* Test that a missing irq domain returns -EPROBE_DEFER */
np = of_find_node_by_path("/testcase-data/testcase-device1");
@@ -1944,6 +1945,7 @@ static void __init of_unittest_platform_populate(void)
irq = platform_get_irq(pdev, 0);
unittest(irq == -EPROBE_DEFER,
"device deferred probe failed - %d\n", irq);
+ of_node_put(np);
/* Test that a parsing failure does not return -EPROBE_DEFER */
np = of_find_node_by_path("/testcase-data/testcase-device2");
@@ -1961,6 +1963,7 @@ static void __init of_unittest_platform_populate(void)
unittest(irq < 0 && irq != -EPROBE_DEFER,
"device parsing error failed - %d\n", irq);
}
+ of_node_put(np);
np = of_find_node_by_path("/testcase-data/platform-tests");
unittest(np, "No testcase data in device tree\n");
--
2.34.1