Skip to content

Commit 9689da7

Browse files
author
John W. Linville
committed
cxl/edac: Fix potential memory leak issues
JIRA: https://issues.redhat.com/browse/RHEL-107284 commit a403fe6 Author: Li Ming <ming.li@zohomail.com> Date: Fri Jun 13 09:16:48 2025 +0800 cxl/edac: Fix potential memory leak issues In cxl_store_rec_gen_media() and cxl_store_rec_dram(), use kmemdup() to duplicate a cxl gen_media/dram event to store the event in a xarray by xa_store(). The cxl gen_media/dram event allocated by kmemdup() should be freed in the case that the xa_store() fails. Fixes: 0b5ccb0 ("cxl/edac: Support for finding memory operation attributes from the current boot") Signed-off-by: Li Ming <ming.li@zohomail.com> Tested-by: Shiju Jose <shiju.jose@huawei.com> Reviewed-by: Shiju Jose <shiju.jose@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20250613011648.102840-1-ming.li@zohomail.com Signed-off-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: John W. Linville <linville@redhat.com>
1 parent 9113b24 commit 9689da7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/cxl/core/edac.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,10 @@ int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt)
11021102
old_rec = xa_store(&array_rec->rec_gen_media,
11031103
le64_to_cpu(rec->media_hdr.phys_addr), rec,
11041104
GFP_KERNEL);
1105-
if (xa_is_err(old_rec))
1105+
if (xa_is_err(old_rec)) {
1106+
kfree(rec);
11061107
return xa_err(old_rec);
1108+
}
11071109

11081110
kfree(old_rec);
11091111

@@ -1130,8 +1132,10 @@ int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt)
11301132
old_rec = xa_store(&array_rec->rec_dram,
11311133
le64_to_cpu(rec->media_hdr.phys_addr), rec,
11321134
GFP_KERNEL);
1133-
if (xa_is_err(old_rec))
1135+
if (xa_is_err(old_rec)) {
1136+
kfree(rec);
11341137
return xa_err(old_rec);
1138+
}
11351139

11361140
kfree(old_rec);
11371141

0 commit comments

Comments
 (0)