[3/3] EDAC/pci: Fix a potential memory leak
Commit Message
From: Lili Li <lili.li@intel.com>
The EDAC PCI core misses kfreeing 'pvt_info' which may result in a memory
leak. Fix it by adding a flag to indicate whether 'pvt_info' is allocated
by the EDAC PCI core and kfreeing 'pvt_info' by the EDAC PCI core when the
flag is set to true.
Fixes: fb8cd45ca39b ("EDAC/pci: Get rid of the silly one-shot memory allocation in edac_pci_alloc_ctl_info()")
Suggested-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Signed-off-by: Lili Li <lili.li@intel.com>
---
drivers/edac/edac_pci.c | 1 +
drivers/edac/edac_pci.h | 5 +++++
drivers/edac/edac_pci_sysfs.c | 2 ++
3 files changed, 8 insertions(+)
@@ -40,6 +40,7 @@ struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
pci->pvt_info = kzalloc(sz_pvt, GFP_KERNEL);
if (!pci->pvt_info)
goto free;
+ pci->pvt_managed_by_edac_core = true;
}
pci->op_state = OP_ALLOC;
@@ -69,6 +69,11 @@ struct edac_pci_ctl_info {
const char *dev_name; /* pci/platform/etc... name */
void *pvt_info; /* pointer to 'private driver' info */
+ /*
+ * Indicate whether the resource pointed by pvt_info is managed by
+ * EDAC core
+ */
+ bool pvt_managed_by_edac_core;
unsigned long start_time; /* edac_pci load start time (jiffies) */
@@ -83,6 +83,8 @@ static void edac_pci_instance_release(struct kobject *kobj)
/* decrement reference count on top main kobj */
kobject_put(edac_pci_top_main_kobj);
+ if (pci->pvt_managed_by_edac_core)
+ kfree(pci->pvt_info);
kfree(pci); /* Free the control struct */
}