mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: Rob Herring <robh@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Saravana Kannan <saravanak@kernel.org>,
	Wentao Liang <vulab@iscas.ac.cn>
Subject: [PATCH v2] of: unittest: Fix np reference leak in of_unittest_bus_3cell_ranges()
Date: Sun, 08 Nov 2026 11:56:44 +0000	[thread overview]
Message-ID: <20261108121000.3772-1-vulab@iscas.ac.cn> (raw)
In-Reply-To: <CAL_JsqJoUywigy2A-tfe4Jg+r_bVsk5utZ0L4qZZu+rF9RXmLg@mail.gmail.com>

of_range_parser_init() can fail when the node lacks a ranges property.
That error path returns without dropping the reference taken by
of_find_node_by_path(). Make the reference cleanup-managed so that it is
released on every return path, rather than adding an of_node_put() to
this one path only.

The candidate was found with static analysis tools; DeepSeek and GPT-6.1
Sol were used to audit it and to help prepare this fix.

Fixes: 3d5089c4263d ("of/address: Add support for 3 address cell bus")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Sorry for the very late reply to your review.
- Use __free(device_node) instead of an extra of_node_put() on the error
  path, as you suggested, so that every return path releases the node.
- Drop Cc: stable@vger.kernel.org.
- The other unittest fixes from that batch need the same rework. I am
  not resending them as a series of individual patches.
- Rebased on current mainline (fa4ad798f6f6). Built with arm64 defconfig
  plus CONFIG_OF_UNITTEST=y and W=1: drivers/of/unittest.o compiles
  without warnings and checkpatch.pl --strict is clean. I could not run
  the unittest at boot, so the error path itself was not exercised.
- Link to v1: https://lore.kernel.org/all/20260917124653.2151894-1-vulab@iscas.ac.cn/

 drivers/of/unittest.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index e255f54f4d76..b6f0ae3e9710 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1366,12 +1366,12 @@ static void __init of_unittest_bus_ranges(void)
 
 static void __init of_unittest_bus_3cell_ranges(void)
 {
-	struct device_node *np;
+	struct device_node *np __free(device_node) =
+		of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
 	struct of_range range;
 	struct of_range_parser parser;
 	int i = 0;
 
-	np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
 	if (!np) {
 		pr_err("missing testcase data\n");
 		return;
@@ -1415,8 +1415,6 @@ static void __init of_unittest_bus_3cell_ranges(void)
 		}
 		i++;
 	}
-
-	of_node_put(np);
 }
 
 static void __init of_unittest_reg(void)
-- 
2.34.1



      reply	other threads:[~2026-11-08 11:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:46 [PATCH] " Wentao Liang
2026-09-17 16:01 ` Rob Herring
2026-11-08 11:56   ` Wentao Liang [this message]

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=20261108121000.3772-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=saravanak@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®