cxl/edac: Fix potential memory leak issues
Li Ming
reviewerPATCH v2 1/1 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.
---
v2:
* Use kfree() instead of __free(kfree). (Jonathan)
base-commit: 87b42c114cdda76c8ad3002f2096699ad5146cb3 cxl/next
--- drivers/cxl/core/edac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/edac.c +6 -2
@@ -1099,8 +1099,10 @@ int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt) old_rec =xa_store (&array_rec->rec_gen_media,le64_to_cpu (rec->media_hdr.phys_addr), rec,GFP_KERNEL ); -if (xa_is_err (old_rec)) +if (xa_is_err (old_rec)) { +kfree (rec);return xa_err (old_rec); + }kfree (old_rec);
@@ -1127,8 +1129,10 @@ int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt) old_rec =xa_store (&array_rec->rec_dram,le64_to_cpu (rec->media_hdr.phys_addr), rec,GFP_KERNEL ); -if (xa_is_err (old_rec)) +if (xa_is_err (old_rec)) { +kfree (rec);return xa_err (old_rec); + }kfree (old_rec);
Signature · 1 line
2.34.1
Quoted 9 lines · On Fri, 13 Jun 2025 09:16:48 +0800 Li Ming <[email protected]> wrote:
In
cxl_store_rec_gen_media()andcxl_store_rec_dram(), usekmemdup()to duplicate a cxl gen_media/dram event to store the event in a xarray byxa_store(). The cxl gen_media/dram event allocated bykmemdup()should be freed in the case that thexa_store()fails.Fixes 0b5ccb0de1e2 ("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]>
LGTM
Quoted 9 lines · Li Ming
In
cxl_store_rec_gen_media()andcxl_store_rec_dram(), usekmemdup()to duplicate a cxl gen_media/dram event to store the event in a xarray byxa_store(). The cxl gen_media/dram event allocated bykmemdup()should be freed in the case that thexa_store()fails.Fixes 0b5ccb0de1e2 ("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]>
[snip]
Quoted 9 lines · Li Ming
In
cxl_store_rec_gen_media()andcxl_store_rec_dram(), usekmemdup()to duplicate a cxl gen_media/dram event to store the event in a xarray byxa_store(). The cxl gen_media/dram event allocated bykmemdup()should be freed in the case that thexa_store()fails.Fixes 0b5ccb0de1e2 ("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]>
[snip]
Quoted 9 lines · Li Ming
In
cxl_store_rec_gen_media()andcxl_store_rec_dram(), usekmemdup()to duplicate a cxl gen_media/dram event to store the event in a xarray byxa_store(). The cxl gen_media/dram event allocated bykmemdup()should be freed in the case that thexa_store()fails.Fixes 0b5ccb0de1e2 ("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]>
Quoted 5 lines
---
v2:
* Usekfree()instead of__free(kfree). (Jonathan)base-commit:
87b42c114cdda76c8ad3002f2096699ad5146cb3cxl/next
Applied to cxl/fixes
In the future, probably best to base against Linus's latest rc rather than cxl/next. Thanks.
Quoted 32 lines
--- drivers/cxl/core/edac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/cxl/core/edac.c +6
-2@@ -1099,8 +1099,10 @@ int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt) old_rec =xa_store (&array_rec->rec_gen_media,le64_to_cpu (rec->media_hdr.phys_addr), rec,GFP_KERNEL ); -if (xa_is_err (old_rec)) +if (xa_is_err (old_rec)) { +kfree (rec);return xa_err (old_rec); + }kfree (old_rec);@@ -1127,8 +1129,10 @@ int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt) old_rec =xa_store (&array_rec->rec_dram,le64_to_cpu (rec->media_hdr.phys_addr), rec,GFP_KERNEL ); -if (xa_is_err (old_rec)) +if (xa_is_err (old_rec)) { +kfree (rec);return xa_err (old_rec); + }kfree (old_rec);