Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: trusted_foundations: fix device_node refcount leak in of_register_trusted_foundations()
@ 2026-06-10  3:08 geoffrey
  0 siblings, 0 replies; only message in thread
From: geoffrey @ 2026-06-10  3:08 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Jonathan Hunter, Stephen Warren, Alexandre Courbot, linux-tegra,
	linux-arm-kernel, linux-kernel, Weigang He

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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-10  3:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10  3:08 [PATCH] firmware: trusted_foundations: fix device_node refcount leak in of_register_trusted_foundations() geoffrey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox