[PATCH] soc: imx8m: Fix missing refcount decrement in error path for np

Javier Carrasco posted 1 patch 1 month, 2 weeks ago
drivers/soc/imx/soc-imx8m.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH] soc: imx8m: Fix missing refcount decrement in error path for np
Posted by Javier Carrasco 1 month, 2 weeks ago
An error path was introduced without including the required call to
of_node_put() to decrement the node's refcount and avoid leaking memory.
If the call to of_clk_get_by_name() for 'clk' fails, the probe returns
without decrementing the refcount.

Use the automatic cleanup facility to fix the bug and protect the code
against new error paths where the call to of_node_put() might be missing
again.

Cc: stable@vger.kernel.org
Fixes: 836fb30949d9 ("soc: imx8m: Enable OCOTP clock before reading the register")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/soc/imx/soc-imx8m.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
index fe111bae38c8..ba8c0bdd60aa 100644
--- a/drivers/soc/imx/soc-imx8m.c
+++ b/drivers/soc/imx/soc-imx8m.c
@@ -99,12 +99,12 @@ static u32 __init imx8mq_soc_revision(void)
 static void __init imx8mm_soc_uid(void)
 {
 	void __iomem *ocotp_base;
-	struct device_node *np;
+	struct device_node *np __free(device_node) =
+		of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
 	struct clk *clk;
 	u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
 		     IMX8MP_OCOTP_UID_OFFSET : 0;
 
-	np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
 	if (!np)
 		return;
 
@@ -125,7 +125,6 @@ static void __init imx8mm_soc_uid(void)
 	clk_disable_unprepare(clk);
 	clk_put(clk);
 	iounmap(ocotp_base);
-	of_node_put(np);
 }
 
 static u32 __init imx8mm_soc_revision(void)

---
base-commit: d61a00525464bfc5fe92c6ad713350988e492b88
change-id: 20241013-soc-imx8m-of_node_put-526a1c8ab540

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>