Skip to contentSkip to conversation

EDAC: Fix memory leak in i5100_init_one

PATCH In review Navid Emamdoost 2 participants 2 messages Nov 21, 2019 EDAC-core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC: Fix memory leak in i5100_init_one

In the implementation of i5100_init_one(), the allocated mci is not correctly released in cases of failure. The release via edac_mc_free() should be reached by label bail_einj and subsequents.

Fixes 52608ba20546 ("i5100_edac: probe for device 19 function 0")
---
 drivers/edac/i5100_edac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/i5100_edac.c +1 -1
index 251f2b692785..710fabd5fba1 100644
@@ -1149,12 +1149,12 @@ static int i5100_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 bail_scrub:
 	priv->scrub_enable = 0;
 	cancel_delayed_work_sync(&(priv->i5100_scrubbing));
-	edac_mc_free(mci);
 
 bail_disable_einj:
 	pci_disable_device(einj);
 
 bail_einj:
+	edac_mc_free(mci);
 	pci_dev_put(einj);
 
 bail_disable_ch1:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Navid Emamdoost

In the implementation of i5100_init_one(), the allocated mci is not correctly released in cases of failure. The release via edac_mc_free() should be reached by label bail_einj and subsequents.

Fixes 52608ba20546 ("i5100_edac: probe for device 19 function 0")
---
 drivers/edac/i5100_edac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/i5100_edac.c +0 -0
index 251f2b692785..710fabd5fba1 100644
@@ -1149,12 +1149,12 @@ static int i5100_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 bail_scrub:

drivers/edac/i5100_edac.c static int i5100_init_one(struct pci_dev *pdev, const struct pci_device_id *id) · line 1158

Quoted 10 lines
drivers/edac/i5100_edac.c +1 -1
 	priv->scrub_enable = 0;
 	cancel_delayed_work_sync(&(priv->i5100_scrubbing));
-	edac_mc_free(mci);
 
 bail_disable_einj:
 	pci_disable_device(einj);
 
 bail_einj:
+	edac_mc_free(mci);
 	pci_dev_put(einj);

The whole error path looks broken:

bail_disable_einj: may *not* call pci_disable_device().

bail_einj: may not call pci_dev_put()

i5100_setup_debugfs() may fail.

etc.

All needs to be fixed. Please review the error path.

Thanks,

-Robert

Quoted 5 lines
drivers/edac/i5100_edac.c +0 -0
 bail_disable_ch1:
Signature · 1 line
2.17.1