Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org
Cc: dave@stgolabs.net, jic23@kernel.org, alison.schofield@intel.com,
	djbw@kernel.org
Subject: Re: [PATCH] cxl/test: Add check after kzalloc() memory in alloc_mock_res()
Date: Thu, 11 Jun 2026 18:16:49 -0700	[thread overview]
Message-ID: <0d025ae2-7f10-40a6-bf9f-fbbe2e448948@intel.com> (raw)
In-Reply-To: <20260611230305.197390-1-dave.jiang@intel.com>



On 6/11/26 4:03 PM, Dave Jiang wrote:
> alloc_mock_res() calls kzalloc() without checking the return value.
> Add scope based resource management to deal with the allocated memory
> cleanly.
> 
> Reported-by: sashiko-bot
> Fixes: 67dcdd4d3b83 ("tools/testing/cxl: Introduce a mocked-up CXL port hierarchy")
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>

Applied to cxl/next
dfe28c859253

> ---
>  tools/testing/cxl/test/cxl.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index 296516eecfd6..e6f68dba85d1 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -433,12 +433,16 @@ static void depopulate_all_mock_resources(void)
>  
>  static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align)
>  {
> -	struct cxl_mock_res *res = kzalloc(sizeof(*res), GFP_KERNEL);
>  	struct genpool_data_align data = {
>  		.align = align,
>  	};
>  	unsigned long phys;
>  
> +	struct cxl_mock_res *res __free(kfree) = kzalloc(sizeof(*res),
> +							 GFP_KERNEL);
> +	if (!res)
> +		return NULL;
> +
>  	INIT_LIST_HEAD(&res->list);
>  	phys = gen_pool_alloc_algo(cxl_mock_pool, size,
>  				   gen_pool_first_fit_align, &data);
> @@ -453,7 +457,7 @@ static struct cxl_mock_res *alloc_mock_res(resource_size_t size, int align)
>  	list_add(&res->list, &mock_res);
>  	mutex_unlock(&mock_res_lock);
>  
> -	return res;
> +	return no_free_ptr(res);
>  }
>  
>  /* Only update CFMWS0 as this is used by the auto region. */
> 
> base-commit: 4549871118cf616eecdd2d939f78e3b9e1dddc48


      parent reply	other threads:[~2026-06-12  1:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 23:03 [PATCH] cxl/test: Add check after kzalloc() memory in alloc_mock_res() Dave Jiang
2026-06-12  0:37 ` Alison Schofield
2026-06-12  1:16 ` Dave Jiang [this message]

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=0d025ae2-7f10-40a6-bf9f-fbbe2e448948@intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    /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