From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Chenyuan Mi <michenyuan@huawei.com>
Cc: <dan.j.williams@intel.com>, <dave.jiang@intel.com>,
<rrichter@amd.com>, <alison.schofield@intel.com>,
<linux-kernel@vger.kernel.org>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH] cxl: Fix memory leak bug in alloc_mock_res()
Date: Mon, 17 Jul 2023 11:50:03 +0100 [thread overview]
Message-ID: <20230717115003.00007f73@Huawei.com> (raw)
In-Reply-To: <20230717041609.1162445-1-michenyuan@huawei.com>
On Mon, 17 Jul 2023 04:16:09 +0000
Chenyuan Mi <michenyuan@huawei.com> wrote:
> When gen_pool_alloc_algo() fails, the error handling path
> forgets to free 'res'. It would cause a memory leak bug.
>
> Fix it by add kfree() in error handling path.
>
> Signed-off-by: Chenyuan Mi <michenyuan@huawei.com>
+CC linux-cxl list
Please make sure to include that for any future CXL patches.
> ---
> tools/testing/cxl/test/cxl.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index 0e78d8e19895..250ffd147067 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -405,8 +405,10 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align)
> INIT_LIST_HEAD(&res->list);
> phys = gen_pool_alloc_algo(cxl_mock_pool, size,
> gen_pool_first_fit_align, &data);
> - if (!phys)
> + if (!phys) {
> + kfree(res);
> return NULL;
> + }
>
> res->range = (struct range) {
> .start = phys,
next prev parent reply other threads:[~2023-07-17 10:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 4:16 [PATCH] cxl: Fix memory leak bug in alloc_mock_res() Chenyuan Mi
2023-07-17 10:50 ` Jonathan Cameron [this message]
2023-07-17 16:19 ` Dave Jiang
2023-07-17 23:49 ` Dan Williams
2023-07-18 2:53 ` Dan Williams
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=20230717115003.00007f73@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michenyuan@huawei.com \
--cc=rrichter@amd.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.