From: geoffrey <geoffreyhe2@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>,
Stephen Warren <swarren@nvidia.com>,
Alexandre Courbot <acourbot@nvidia.com>,
linux-tegra@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Weigang He <geoffreyhe2@gmail.com>
Subject: [PATCH] firmware: trusted_foundations: fix device_node refcount leak in of_register_trusted_foundations()
Date: Wed, 10 Jun 2026 13:08:00 +1000 [thread overview]
Message-ID: <20260610030800.2100685-1-geoffreyhe2@gmail.com> (raw)
From: Weigang He <geoffreyhe2@gmail.com>
of_register_trusted_foundations() obtains a reference to the
"tlm,trusted-foundations" device node via of_find_compatible_node(),
which returns the node with its refcount incremented, but the
reference is never dropped. The function has four exits:
- early return when the node is absent (no reference taken)
- panic on a missing "tlm,version-major" (leaks one reference)
- panic on a missing "tlm,version-minor" (leaks one reference)
- normal return after register_trusted_foundations() (leaks one ref)
On a normal Tegra boot using Trusted Foundations the node is found and
the function returns normally, leaking one device_node reference for
the lifetime of the system.
Annotate the node with the __free(device_node) cleanup attribute so the
reference is released automatically on every exit path.
Found by static analysis tool CodeQL.
Fixes: d9a1beaa10e8 ("ARM: add basic support for Trusted Foundations")
Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
---
drivers/firmware/trusted_foundations.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/trusted_foundations.c b/drivers/firmware/trusted_foundations.c
index 1389fa9418a7b..43a2a417528f4 100644
--- a/drivers/firmware/trusted_foundations.c
+++ b/drivers/firmware/trusted_foundations.c
@@ -159,11 +159,11 @@ void register_trusted_foundations(struct trusted_foundations_platform_data *pd)
void of_register_trusted_foundations(void)
{
- struct device_node *node;
+ struct device_node *node __free(device_node) =
+ of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
struct trusted_foundations_platform_data pdata;
int err;
- node = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
if (!node)
return;
base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193
--
2.43.0
reply other threads:[~2026-06-10 3:08 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=20260610030800.2100685-1-geoffreyhe2@gmail.com \
--to=geoffreyhe2@gmail.com \
--cc=acourbot@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=swarren@nvidia.com \
--cc=thierry.reding@gmail.com \
/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