Skip to contentSkip to conversation

clocksource: timer-imx-gpt: fix potential memory leak

PATCH Applied Jacky Bai 3 participants 3 messages Oct 9, 2023 – Oct 27, 2023

Subsystems (2)
lore
Share & tools
lore

Jacky Bai

author
#0 lore raw

PATCH 1/1 clocksource: timer-imx-gpt: fix potential memory leak

Fix coverity Issue CID 250382: Resource leak (RESOURCE_LEAK). Add kfree when error return.

---
 drivers/clocksource/timer-imx-gpt.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/clocksource/timer-imx-gpt.c +13 -5
index 28ab4f1a7c71..6a878d227a13 100644
@@ -434,12 +434,16 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 		return -ENOMEM;
 
 	imxtm->base = of_iomap(np, 0);
-	if (!imxtm->base)
-		return -ENXIO;
+	if (!imxtm->base) {
+		ret = -ENXIO;
+		goto err_kfree;
+	}
 
 	imxtm->irq = irq_of_parse_and_map(np, 0);
-	if (imxtm->irq <= 0)
-		return -EINVAL;
+	if (imxtm->irq <= 0) {
+		ret = -EINVAL;
+		goto err_kfree;
+	}
 
 	imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");
 
@@ -452,11 +456,15 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 
 	ret = _mxc_timer_init(imxtm);
 	if (ret)
-		return ret;
+		goto err_kfree;
 
 	initialized = 1;
 
 	return 0;
+
+err_kfree:
+	kfree(imxtm);
+	return ret;
 }
 
 static int __init imx1_timer_init_dt(struct device_node *np)
Signature · 7 lines
2.34.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

Hi Jacky,

Quoted 6 lines · Jacky Bai

Fix coverity Issue CID 250382: Resource leak (RESOURCE_LEAK). Add kfree when error return.

---

In the future, add lkml@ in Cc also. Also the subject has the format:

clocksource/drivers/<mydriver> : [AZ].*

Applied [with the subject fixed]

Thanks

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
merge bot Applied
#2 lore raw

[tip: timers/core] clocksource/drivers/timer-imx-gpt: Fix potential memory leak

In reply to Jacky Bai
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     8051a993ce222a5158bccc6ac22ace9253dd71cb
Gitweb:        https://git.kernel.org/tip/8051a993ce222a5158bccc6ac22ace9253dd71cb
Author:        Jacky Bai <[email protected]>
AuthorDate:    Mon, 09 Oct 2023 16:39:22 +08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Wed, 11 Oct 2023 10:10:34 +02:00

clocksource/drivers/timer-imx-gpt: Fix potential memory leak

Fix coverity Issue CID 250382: Resource leak (RESOURCE_LEAK). Add kfree when error return.

---
 drivers/clocksource/timer-imx-gpt.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/clocksource/timer-imx-gpt.c +13 -5
index 28ab4f1..6a878d2 100644
@@ -434,12 +434,16 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 		return -ENOMEM;
 
 	imxtm->base = of_iomap(np, 0);
-	if (!imxtm->base)
-		return -ENXIO;
+	if (!imxtm->base) {
+		ret = -ENXIO;
+		goto err_kfree;
+	}
 
 	imxtm->irq = irq_of_parse_and_map(np, 0);
-	if (imxtm->irq <= 0)
-		return -EINVAL;
+	if (imxtm->irq <= 0) {
+		ret = -EINVAL;
+		goto err_kfree;
+	}
 
 	imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");
 
@@ -452,11 +456,15 @@ static int __init mxc_timer_init_dt(struct device_node *np,  enum imx_gpt_type t
 
 	ret = _mxc_timer_init(imxtm);
 	if (ret)
-		return ret;
+		goto err_kfree;
 
 	initialized = 1;
 
 	return 0;
+
+err_kfree:
+	kfree(imxtm);
+	return ret;
 }
 
 static int __init imx1_timer_init_dt(struct device_node *np)