Skip to contentSkip to conversation

clk: imx: scu: fix memleak on platform_device_add() fails

PATCH Applied Lin Yujun 2 participants 4 messages Sep 14, 2022 – Oct 1, 2022

Subsystems (3)
lore
Share & tools
lore

Lin Yujun

author
#0 lore raw

PATCH 1/1 clk: imx: scu: fix memleak on platform_device_add() fails

No error handling is performed when platform_device_add() fails. Add error processing before return, and modified the return value.

Fixes 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
---
 drivers/clk/imx/clk-scu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-scu.c +5 -1
index c56e406138db..1e6870f3671f 100644
@@ -695,7 +695,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
 		pr_warn("%s: failed to attached the power domain %d\n",
 			name, ret);
 
-	platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret) {
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
 
 	/* For API backwards compatiblilty, simply return NULL for success */
 	return NULL;
Signature · 1 line
2.17.1
#1 lore raw

kindly ping

Quoted 27 lines · Lin Yujun

No error handling is performed when platform_device_add() fails. Add error processing before return, and modified the return value.

Fixes 77d8f3068c63 ("clk: imx: scu: add two cells binding support")
---
  drivers/clk/imx/clk-scu.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-scu.c +5 -1
index c56e406138db..1e6870f3671f 100644
@@ -695,7 +695,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
  		pr_warn("%s: failed to attached the power domain %d\n",
  			name, ret);
 
-	platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret) {
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
 
  	/* For API backwards compatiblilty, simply return NULL for success */
  	return NULL;
maintainer Applied
#3 lore raw
In reply to Lin Yujun

Quoting Lin Yujun (2022-09-13 20:32:06)

Quoted 7 lines

No error handling is performed when platform_device_add() fails. Add error processing before return, and modified the return value.

Fixes 77d8f3068c63 ("clk: imx: scu: add two cells binding support")

---

Applied to clk-next