From: Shiju Jose <shiju.jose@huawei.com>
To: Li Ming <ming.li@zohomail.com>,
"dave@stgolabs.net" <dave@stgolabs.net>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
"dave.jiang@intel.com" <dave.jiang@intel.com>,
"alison.schofield@intel.com" <alison.schofield@intel.com>,
"vishal.l.verma@intel.com" <vishal.l.verma@intel.com>,
"ira.weiny@intel.com" <ira.weiny@intel.com>,
"dan.j.williams@intel.com" <dan.j.williams@intel.com>
Cc: "linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/1] cxl/edac: Fix potential memory leak issues
Date: Wed, 11 Jun 2025 10:44:01 +0000 [thread overview]
Message-ID: <d44aac6a202d4e1695a52ddc0e33a735@huawei.com> (raw)
In-Reply-To: <20250611033542.96184-1-ming.li@zohomail.com>
>-----Original Message-----
>From: Li Ming <ming.li@zohomail.com>
>Sent: 11 June 2025 04:36
>To: dave@stgolabs.net; Jonathan Cameron <jonathan.cameron@huawei.com>;
>dave.jiang@intel.com; alison.schofield@intel.com; vishal.l.verma@intel.com;
>ira.weiny@intel.com; dan.j.williams@intel.com; Shiju Jose
><shiju.jose@huawei.com>
>Cc: linux-cxl@vger.kernel.org; linux-kernel@vger.kernel.org; Li Ming
><ming.li@zohomail.com>
>Subject: [PATCH 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.
>
>Fixes: 0b5ccb0de1e2 ("cxl/edac: Support for finding memory operation
>attributes from the current boot")
>Signed-off-by: Li Ming <ming.li@zohomail.com>
Thanks Ming for fixing.
Tested-by: Shiju Jose <shiju.jose@huawei.com>
Reviewed-by: Shiju Jose <shiju.jose@huawei.com>
>---
>base-commit: 87b42c114cdda76c8ad3002f2096699ad5146cb3 cxl/fixes
>---
> drivers/cxl/core/edac.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/cxl/core/edac.c b/drivers/cxl/core/edac.c index
>2cbc664e5d62..b4c5c23a45d4 100644
>--- a/drivers/cxl/core/edac.c
>+++ b/drivers/cxl/core/edac.c
>@@ -1086,13 +1086,13 @@ static void cxl_del_overflow_old_recs(struct xarray
>*rec_xarray) int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union
>cxl_event *evt) {
> struct cxl_mem_err_rec *array_rec = cxlmd->err_rec_array;
>- struct cxl_event_gen_media *rec;
> void *old_rec;
>
> if (!IS_ENABLED(CONFIG_CXL_EDAC_MEM_REPAIR) || !array_rec)
> return 0;
>
>- rec = kmemdup(&evt->gen_media, sizeof(*rec), GFP_KERNEL);
>+ struct cxl_event_gen_media *rec __free(kfree) =
>+ kmemdup(&evt->gen_media, sizeof(*rec), GFP_KERNEL);
> if (!rec)
> return -ENOMEM;
>
>@@ -1106,6 +1106,7 @@ int cxl_store_rec_gen_media(struct cxl_memdev
>*cxlmd, union cxl_event *evt)
>
> cxl_del_expired_gmedia_recs(&array_rec->rec_gen_media, rec);
> cxl_del_overflow_old_recs(&array_rec->rec_gen_media);
>+ retain_and_null_ptr(rec);
>
> return 0;
> }
>@@ -1114,13 +1115,13 @@
>EXPORT_SYMBOL_NS_GPL(cxl_store_rec_gen_media, "CXL"); int
>cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt) {
> struct cxl_mem_err_rec *array_rec = cxlmd->err_rec_array;
>- struct cxl_event_dram *rec;
> void *old_rec;
>
> if (!IS_ENABLED(CONFIG_CXL_EDAC_MEM_REPAIR) || !array_rec)
> return 0;
>
>- rec = kmemdup(&evt->dram, sizeof(*rec), GFP_KERNEL);
>+ struct cxl_event_dram *rec __free(kfree) =
>+ kmemdup(&evt->dram, sizeof(*rec), GFP_KERNEL);
> if (!rec)
> return -ENOMEM;
>
>@@ -1134,6 +1135,7 @@ int cxl_store_rec_dram(struct cxl_memdev *cxlmd,
>union cxl_event *evt)
>
> cxl_del_expired_dram_recs(&array_rec->rec_dram, rec);
> cxl_del_overflow_old_recs(&array_rec->rec_dram);
>+ retain_and_null_ptr(rec);
>
> return 0;
> }
>--
>2.34.1
next prev parent reply other threads:[~2025-06-11 10:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 3:35 Li Ming
2025-06-11 10:44 ` Shiju Jose [this message]
2025-06-11 13:16 ` Jonathan Cameron
2025-06-12 1:05 ` Li Ming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d44aac6a202d4e1695a52ddc0e33a735@huawei.com \
--to=shiju.jose@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®