Linux CXL
 help / color / mirror / Atom feed
From: "Zhijian Li (Fujitsu)" <lizhijian@fujitsu.com>
To: Dan Williams <dan.j.williams@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	"dave@stgolabs.net" <dave@stgolabs.net>,
	"jonathan.cameron@huawei.com" <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>,
	"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cxl/region: Fix memregion leaks in devm_cxl_add_region()
Date: Tue, 7 May 2024 05:28:37 +0000	[thread overview]
Message-ID: <03868282-b44d-4da8-bda6-c8ae92273992@fujitsu.com> (raw)
In-Reply-To: <66350bb1d3817_1aefb294ba@dwillia2-mobl3.amr.corp.intel.com.notmuch>



On 04/05/2024 00:07, Dan Williams wrote:
> Zhijian Li (Fujitsu) wrote:
>>> I'm not following what the problem is you are trying to fix.  This seems
>>> like it just moves the memregion_free() around a bit but the logic is the
>>> same.
>>
>> This patch not only memregion_free(id) out of cxl_region_alloc() but
>> also add an  extra memregion_free(id) in EINVAL case which led to a
>> memory leak previously
>>
> 
> I think I would prefer to just eliminate that failure case, something
> like:

It sounds good to me. I will update it in V2

Thanks
Zhijian


> 
> -- >8 --
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 5c186e0a39b9..95ba32f8649c 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2352,15 +2352,6 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
>          struct device *dev;
>          int rc;
>   
> -       switch (mode) {
> -       case CXL_DECODER_RAM:
> -       case CXL_DECODER_PMEM:
> -               break;
> -       default:
> -               dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
> -               return ERR_PTR(-EINVAL);
> -       }
> -
>          cxlr = cxl_region_alloc(cxlrd, id);
>          if (IS_ERR(cxlr))
>                  return cxlr;
> @@ -2415,6 +2406,15 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
>   {
>          int rc;
>   
> +       switch (mode) {
> +       case CXL_DECODER_RAM:
> +       case CXL_DECODER_PMEM:
> +               break;
> +       default:
> +               dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
> +               return ERR_PTR(-EINVAL);
> +       }
> +
>          rc = memregion_alloc(GFP_KERNEL);
>          if (rc < 0)
>                  return ERR_PTR(rc);
> 

  reply	other threads:[~2024-05-07  5:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-28  5:37 [PATCH] cxl/region: Fix memregion leaks in devm_cxl_add_region() Li Zhijian
2024-04-29 16:23 ` Ira Weiny
     [not found]   ` <TY1PR01MB1562E0A5EA4F95FFE0F39602A51F2@TY1PR01MB1562.jpnprd01.prod.outlook.com>
2024-05-03 16:07     ` Dan Williams
2024-05-07  5:28       ` Zhijian Li (Fujitsu) [this message]
2024-05-07  2:42   ` Zhijian Li (Fujitsu)
2024-05-07 15:52     ` Dave Jiang
2024-05-09  3:11       ` Zhijian Li (Fujitsu)

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=03868282-b44d-4da8-bda6-c8ae92273992@fujitsu.com \
    --to=lizhijian@fujitsu.com \
    --cc=Jonathan.Cameron@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=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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