Skip to contentSkip to conversation

EDAC: highbank: Fix memory leak in highbank_mc_probe

PATCH Applied Miaoqian Lin 3 participants 3 messages Dec 29, 2022 – Jan 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC: highbank: Fix memory leak in highbank_mc_probe

edac_mc_alloc() allocates memory. The memory are not released when devres_open_group() fails, which causes memory leak. Call edac_mc_free() in the error handling to fix this.

Fixes a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")

---
altr_sdram_probe() performs similar operations,
I take it as reference.

---
 drivers/edac/highbank_mc_edac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/edac/highbank_mc_edac.c +5 -2
index 61b76ec226af..19fba258ae10 100644
@@ -174,8 +174,10 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	drvdata = mci->pvt_info;
 	platform_set_drvdata(pdev, mci);
 
-	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
-		return -ENOMEM;
+	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
+		res = -ENOMEM;
+		goto free;
+	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!r) {
@@ -243,6 +245,7 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	edac_mc_del_mc(&pdev->dev);
 err:
 	devres_release_group(&pdev->dev, NULL);
+free:
 	edac_mc_free(mci);
 	return res;
 }
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

On Thu, 29 Dec 2022 09:48:24 +0400
Miaoqian Lin <[email protected]> wrote:

Hi,

Quoted 3 lines

edac_mc_alloc() allocates memory. The memory are not released when devres_open_group() fails, which causes memory leak. Call edac_mc_free() in the error handling to fix this.

Yes, this looks correct.

Cheers,
Andre

Quoted 34 lines
Fixes a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")

---
altr_sdram_probe() performs similar operations,
I take it as reference.

---
 drivers/edac/highbank_mc_edac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/edac/highbank_mc_edac.c +5 -2
index 61b76ec226af..19fba258ae10 100644
@@ -174,8 +174,10 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	drvdata = mci->pvt_info;
 	platform_set_drvdata(pdev, mci);
 
-	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
-		return -ENOMEM;
+	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
+		res = -ENOMEM;
+		goto free;
+	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!r) {
@@ -243,6 +245,7 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	edac_mc_del_mc(&pdev->dev);
 err:
 	devres_release_group(&pdev->dev, NULL);
+free:
 	edac_mc_free(mci);
 	return res;
 }
maintainer Applied
#2 lore raw
In reply to Miaoqian Lin
Quoted 4 lines · Miaoqian Lin

edac_mc_alloc() allocates memory. The memory are not released when devres_open_group() fails, which causes memory leak. Call edac_mc_free() in the error handling to fix this.

Quoted 8 lines
Fixes a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")

---
altr_sdram_probe() performs similar operations,
I take it as reference.

---
 drivers/edac/highbank_mc_edac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette