[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230603144131.832804-1-linmiaohe@huawei.com>
Date: Sat, 3 Jun 2023 22:41:31 +0800
From: Miaohe Lin <linmiaohe@...wei.com>
To: <tony.luck@...el.com>, <bp@...en8.de>
CC: <james.morse@....com>, <mchehab@...nel.org>, <rric@...nel.org>,
<linux-edac@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linmiaohe@...wei.com>
Subject: [PATCH] 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 <linmiaohe@...wei.com>
---
drivers/edac/edac_mc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 6faeb2ab3960..89dc5954d19e 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -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;
--
2.27.0
Powered by blists - more mailing lists