[PATCH] soc/tegra: Avoid leak OF node on error

From: cgel . zte
Date: Mon May 23 2022 - 07:12:34 EST


From: Minghao Chi <chi.minghao@xxxxxxxxxx>

The OF node should be put before returning error in tegra_init_soc(),
otherwise node's refcount will be leaked.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Minghao Chi <chi.minghao@xxxxxxxxxx>
---
drivers/soc/tegra/fuse/fuse-tegra.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index b0a8405dbdb1..ab3e4dc6dc6e 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -612,11 +612,10 @@ static int __init tegra_init_soc(void)

/* make sure we're running on Tegra */
np = of_find_matching_node(NULL, tegra_fuse_match);
+ of_node_put(np);
if (!np)
return 0;

- of_node_put(np);
-
soc = tegra_soc_device_register();
if (IS_ERR(soc)) {
pr_err("failed to register SoC device: %ld\n", PTR_ERR(soc));
--
2.25.1