All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH] of: unittest: fix node leak in phandle remapping test
Date: Tue, 03 Nov 2026 10:57:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-195088@kernel.org> (raw)
In-Reply-To: <20261103104235.1373591-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] of: unittest: leak of p[] nodes in of_unittest_parse_phandle_with_args_map()
--

commit 76085e24075478d56a6949c4d7365c6d0d60c538
Author: Wentao Liang <vulab@iscas.ac.cn>

of: unittest: fix node leak in phandle remapping test

This commit releases the device_node reference for the consumer node and
adds cleanup for the provider node references when a provider lookup fails
in of_unittest_parse_phandle_with_args_map().

> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index e255f54f4d760..f240b1175211b 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -578,6 +578,9 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
>  	for (i = 0; i < ARRAY_SIZE(p); ++i) {
>  		if (!p[i]) {
>  			pr_err("missing testcase data\n");
> +			while (i > 0)
> +				of_node_put(p[--i]);
> +			of_node_put(np);
>  			return;
>  		}
>  		prefs[i] = OF_KREF_READ(p[i]);

[Severity: Medium]
Does this error path still leak device_node references in p[i + 1] through
p[5]?

In drivers/of/unittest.c:of_unittest_parse_phandle_with_args_map(), all six
provider nodes are looked up before the validation loop begins:

	p[0] = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
	p[1] = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
	p[2] = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
	p[3] = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
	p[4] = of_find_node_by_path("/testcase-data/phandle-tests/provider4");
	p[5] = of_find_node_by_path("/testcase-data/phandle-tests/provider5");
	for (i = 0; i < ARRAY_SIZE(p); ++i) {
		if (!p[i]) {

If p[i] is NULL for an earlier entry (for example p[0]) while subsequent
lookups in p[i + 1 .. 5] succeeded, unwinding only from i down to 0 leaves
the non-NULL references in the remaining elements of p[] unreleased.

Since of_node_put() safely accepts NULL pointers, should this loop over the
entire p[] array (and update the commit message, which currently states that
the references were acquired by preceding loop iterations)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261103104235.1373591-1-vulab@iscas.ac.cn?part=1

  reply	other threads:[~2026-11-03 10:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 10:42 [PATCH] of: unittest: fix node leak in phandle remapping test Wentao Liang
2026-11-03 10:57 ` sashiko-bot [this message]
2026-11-03 11:09 ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-195088@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.