firmware: trusted_foundations: fix device_node refcount leak in of_register_trusted_foundations()
PATCH 1/1 firmware: trusted_foundations: fix device_node refcount leak in of_register_trusted_foundations()
From: Weigang He <[email protected]>
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.
--- drivers/firmware/trusted_foundations.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/trusted_foundations.c +2 -2
@@ -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
Signature · 1 line
2.43.0