Skip to contentSkip to conversation

firmware: Hold a reference for of_find_compatible_node()

PATCH New Liang He 1 participant 1 message Jun 28, 2022

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 firmware: Hold a reference for of_find_compatible_node()

In of_register_trusted_foundations(), we need to hold the reference returned by of_find_compatible_node() and then use it to call of_node_put() for refcount balance.

---
v2: use 'check-and-put' coding style
v1: hold ref returned by of_find_xxx

v1 link: https://lore.kernel.org/all/[email protected]/

 include/linux/firmware/trusted_foundations.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
include/linux/firmware/trusted_foundations.h +6 -2
index be5984bda592..931b6c5c72df 100644
@@ -71,12 +71,16 @@ static inline void register_trusted_foundations(
 
 static inline void of_register_trusted_foundations(void)
 {
+	struct device_node *np = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
+
+	if (!np)
+		return;
+	of_node_put(np);
 	/*
 	 * If we find the target should enable TF but does not support it,
 	 * fail as the system won't be able to do much anyway
 	 */
-	if (of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations"))
-		register_trusted_foundations(NULL);
+	register_trusted_foundations(NULL);
 }
 
 static inline bool trusted_foundations_registered(void)
Signature · 1 line
2.25.1