[PATCH] kunit: unregister software node when fwnode lookup fails
From: Jiangshan Yi
Date: Tue Nov 17 2026 - 05:07:40 EST
If software_node_fwnode() returns NULL right after a successful
software_node_register(), the error path leaves the node registered
with no cleanup. Unregister it before returning the error to match
the behaviour of the other helpers in this file.
Fixes: 9fdbdb528488 ("kunit: provide a set of fwnode-oriented helpers")
Signed-off-by: Jiangshan Yi <yijiangshan@xxxxxxxxxx>
---
lib/kunit/fwnode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/kunit/fwnode.c b/lib/kunit/fwnode.c
index a58ce0984d76..5a98e5e75f22 100644
--- a/lib/kunit/fwnode.c
+++ b/lib/kunit/fwnode.c
@@ -74,8 +74,10 @@ kunit_software_node_register(struct kunit *test,
return ERR_PTR(ret);
fwnode = software_node_fwnode(swnode);
- if (WARN_ON(!fwnode))
+ if (WARN_ON(!fwnode)) {
+ software_node_unregister(swnode);
return ERR_PTR(-ENOENT);
+ }
ret = kunit_add_action_or_reset(test, software_node_unregister_wrapper,
(void *)swnode);
--
2.25.1