Skip to contentSkip to conversation

EDAC/amd64: fix possible leak in hw_info_get()

PATCH In review Peng Wu 2 participants 2 messages Nov 10, 2022

Subsystems (2)
lore
Share & tools
lore

Peng Wu

author
#0 lore raw

PATCH 1/1 EDAC/amd64: fix possible leak in hw_info_get()

Add missing kfree() in an error path in hw_info_get() to avoid a memory leak.

Fixes 80355a3b2db9 ("EDAC/amd64: Gather hardware information early")
---
 drivers/edac/amd64_edac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/edac/amd64_edac.c +3 -1
index 2f854feeeb23..b64b774eb974 100644
@@ -4108,8 +4108,10 @@ static int hw_info_get(struct amd64_pvt *pvt)
 	}
 
 	ret = reserve_mc_sibling_devs(pvt, pci_id1, pci_id2);
-	if (ret)
+	if (ret) {
+		kfree(pvt->umc);
 		return ret;
+	}
 
 	read_mc_regs(pvt);
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 16 lines · Peng Wu

Add missing kfree() in an error path in hw_info_get() to avoid a memory leak.

Fixes 80355a3b2db9 ("EDAC/amd64: Gather hardware information early")
---
 drivers/edac/amd64_edac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/edac/amd64_edac.c +0 -0
index 2f854feeeb23..b64b774eb974 100644
@@ -4108,8 +4108,10 @@ static int hw_info_get(struct amd64_pvt *pvt)
 	}

drivers/edac/amd64_edac.c static int hw_info_get(struct amd64_pvt *pvt) · line 4117

Quoted 10 lines
drivers/edac/amd64_edac.c +3 -1
 
 	ret = reserve_mc_sibling_devs(pvt, pci_id1, pci_id2);
-	if (ret)
+	if (ret) {
+		kfree(pvt->umc);
 		return ret;
+	}
 
 	read_mc_regs(pvt);
 

Hi Peng Wu,

Thank you for your submisssion.

This is already handled in the error path.

If hw_info_get() fails, then we jump to the "err_enable" label in probe_one_instance(). This calls hw_info_put() which frees the "umc" array.

Is there a case where this path isn't followed?

Thanks,
Yazen