Skip to content

Commit a403fe6

Browse files
MingLi-4davejiang
authored andcommitted
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 <[email protected]> Tested-by: Shiju Jose <[email protected]> Reviewed-by: Shiju Jose <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 85cc50b commit a403fe6

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
@@ -1103,8 +1103,10 @@ int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt)
11031103
old_rec = xa_store(&array_rec->rec_gen_media,
11041104
le64_to_cpu(rec->media_hdr.phys_addr), rec,
11051105
GFP_KERNEL);
1106-
if (xa_is_err(old_rec))
1106+
if (xa_is_err(old_rec)) {
1107+
kfree(rec);
11071108
return xa_err(old_rec);
1109+
}
11081110

11091111
kfree(old_rec);
11101112

@@ -1131,8 +1133,10 @@ int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt)
11311133
old_rec = xa_store(&array_rec->rec_dram,
11321134
le64_to_cpu(rec->media_hdr.phys_addr), rec,
11331135
GFP_KERNEL);
1134-
if (xa_is_err(old_rec))
1136+
if (xa_is_err(old_rec)) {
1137+
kfree(rec);
11351138
return xa_err(old_rec);
1139+
}
11361140

11371141
kfree(old_rec);
11381142

0 commit comments

Comments
 (0)