public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuho Choi <dbgh9129@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: linux-kernel@vger.kernel.org, Yuho Choi <dbgh9129@gmail.com>
Subject: [PATCH v1] bus: arm-cci: Fix OF node refcount leak in cci_probe()
Date: Fri,  1 May 2026 14:27:07 -0400	[thread overview]
Message-ID: <20260501182707.2668421-1-dbgh9129@gmail.com> (raw)

of_find_matching_node() returns a device node with its reference count
incremented. cci_probe() returns without dropping that reference when
the matched node is unavailable, when controller mapping fails, and
after cci_probe_ports() returns.

Route all exits after the lookup through a common cleanup label and drop
the node with of_node_put(). This is also safe for the no-match case
because of_node_put(NULL) is allowed.

Fixes: ed69bdd8fd9b ("drivers: bus: add ARM CCI support")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 drivers/bus/arm-cci.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
index 7f2baf057128..f5993380d511 100644
--- a/drivers/bus/arm-cci.c
+++ b/drivers/bus/arm-cci.c
@@ -538,8 +538,10 @@ static int cci_probe(void)
 	struct resource res;
 
 	np = of_find_matching_node(NULL, arm_cci_matches);
-	if (!of_device_is_available(np))
-		return -ENODEV;
+	if (!of_device_is_available(np)) {
+		ret = -ENODEV;
+		goto out_put_node;
+	}
 
 	ret = of_address_to_resource(np, 0, &res);
 	if (!ret) {
@@ -548,10 +550,15 @@ static int cci_probe(void)
 	}
 	if (ret || !cci_ctrl_base) {
 		WARN(1, "unable to ioremap CCI ctrl\n");
-		return -ENXIO;
+		ret = -ENXIO;
+		goto out_put_node;
 	}
 
-	return cci_probe_ports(np);
+	ret = cci_probe_ports(np);
+
+out_put_node:
+	of_node_put(np);
+	return ret;
 }
 
 static int cci_init_status = -EAGAIN;
-- 
2.43.0


                 reply	other threads:[~2026-05-01 18:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260501182707.2668421-1-dbgh9129@gmail.com \
    --to=dbgh9129@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.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