[PATCH] crypto: nx - Fix double of_node_put() in find_nx_device_tree()

From: Zijie Zhao via B4 Relay

Date: Tue Dec 01 2026 - 15:36:54 EST


From: Zijie Zhao <zzjas98@xxxxxxxxx>

nx_powernv_probe_vas() walks the children of an NX node with
for_each_child_of_node_scoped() and passes each child to
find_nx_device_tree(). When the child is a matching NX FIFO node and
vas_cfg_coproc_info() fails, find_nx_device_tree() drops the child
reference with of_node_put(). The caller then returns the error, and
the scoped iterator drops the same reference again when it goes out of
scope.

The helper never took a reference of its own, so the put there is
wrong. It was correct when the caller just returned, but
commit 1406f0f34402 ("crypto: nx - add missing call to of_node_put()")
added a second put in the caller's error path, which
commit f7738c07b5fe ("crypto: nx - Simplify with scoped for each OF
child loop") later turned into the scoped iterator cleanup.

With CONFIG_OF_DYNAMIC the node refcount is decremented once too often
when NX VAS configuration fails at init, which can make
of_node_release() complain about a bad of_node_put() on a node that is
still in the tree.

Remove the put from find_nx_device_tree() and leave the reference to
the iterator that owns it.

Jonathan Cameron pointed out this double put in 2024 while reviewing an
earlier conversion of this loop to the scoped iterator, but no fix
followed.

Found by a static analysis tool.

The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Fixes: 1406f0f34402 ("crypto: nx - add missing call to of_node_put()")
Link: https://lore.kernel.org/all/20240204210804.0febf2fc@jic23-huawei/
Signed-off-by: Zijie Zhao <zzjas98@xxxxxxxxx>
---
The put is removed from the helper rather than the caller because, since
the switch to for_each_child_of_node_scoped(), the caller no longer has
an explicit put to drop. The same one-line removal also applies to trees
that still have the explicit of_node_put() in nx_powernv_probe_vas().

Testing:
- Compile-tested on powerpc (allmodconfig, W=1):
drivers/crypto/nx/nx-common-powernv.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/crypto/nx/nx-common-powernv.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/crypto/nx/nx-common-powernv.c b/drivers/crypto/nx/nx-common-powernv.c
index d6185740ff93..92995af3ff29 100644
--- a/drivers/crypto/nx/nx-common-powernv.c
+++ b/drivers/crypto/nx/nx-common-powernv.c
@@ -895,11 +895,8 @@ static int __init find_nx_device_tree(struct device_node *dn, int chip_id,
{
int ret = 0;

- if (of_device_is_compatible(dn, devname)) {
+ if (of_device_is_compatible(dn, devname))
ret = vas_cfg_coproc_info(dn, chip_id, vasid, type, ct);
- if (ret)
- of_node_put(dn);
- }

return ret;
}

---
base-commit: e1ec0b1e859b0f2261d64b3db95991c2da627af4
change-id: 20261201-kbug-l002-nx-powernv-3cfab8a41961

Best regards,
--
Zijie Zhao <zzjas98@xxxxxxxxx>