EDAC/mc: fix potential memoryleak in edac_mc_alloc()
PATCH 1/1 EDAC/mc: fix potential memoryleak in edac_mc_alloc()
When fails to allocate memory for layers or pvt_info, _edac_mc_free() will be called to release the resource of edac mc but mci->dev is not even initialized at that time. _edac_mc_free() will fail to release the allocated memory.
Fixes 0bbb265f7089 ("EDAC/mc: Get rid of silly one-shot struct allocation in edac_mc_alloc()")
Signed-off-by Miaohe Lin <[email protected]>
--- drivers/edac/edac_mc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/edac/edac_mc.c +2 -3
@@ -364,6 +364,8 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num, mci =kzalloc (sizeof (struct mem_ctl_info ),GFP_KERNEL );if (!mci)return NULL ; + mci->dev.release = mci_release; +device_initialize (&mci->dev); mci->layers =kcalloc (n_layers,sizeof (struct edac_mc_layer ),GFP_KERNEL );if (!mci->layers)
@@ -373,9 +375,6 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num,if (!mci->pvt_info) goto error; - mci->dev.release = mci_release; -device_initialize (&mci->dev); -/* setup index and various internal pointers */ mci->mc_idx = mc_num; mci->tot_dimms = tot_dimms;
Signature · 1 line
2.27.0
Quoted 4 lines · Miaohe Lin
When fails to allocate memory for layers or
pvt_info,_edac_mc_free()will be called to release the resource of edac mc butmci->devis not even initialized at that time._edac_mc_free()will fail to release the allocated memory.
friendly ping.. :)
Quoted 31 lines
Fixes 0bbb265f7089 ("EDAC/mc: Get rid of silly one-shot struct allocation in edac_mc_alloc()")Signed-off-by Miaohe Lin <[email protected]>--- drivers/edac/edac_mc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/edac/edac_mc.c +2
-3@@ -364,6 +364,8 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num, mci =kzalloc (sizeof (struct mem_ctl_info ),GFP_KERNEL );if (!mci)return NULL ; + mci->dev.release = mci_release; +device_initialize (&mci->dev); mci->layers =kcalloc (n_layers,sizeof (struct edac_mc_layer ),GFP_KERNEL );if (!mci->layers)@@ -373,9 +375,6 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num,if (!mci->pvt_info) goto error; - mci->dev.release = mci_release; -device_initialize (&mci->dev); -/* setup index and various internal pointers */ mci->mc_idx = mc_num; mci->tot_dimms = tot_dimms;