Linux CXL
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: "Zhijian Li (Fujitsu)" <lizhijian@fujitsu.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>,
	"dan.j.williams@intel.com" <dan.j.williams@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: Fri, 3 May 2024 09:07:13 -0700	[thread overview]
Message-ID: <66350bb1d3817_1aefb294ba@dwillia2-mobl3.amr.corp.intel.com.notmuch> (raw)
In-Reply-To: <TY1PR01MB1562E0A5EA4F95FFE0F39602A51F2@TY1PR01MB1562.jpnprd01.prod.outlook.com>

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:

-- >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);

  parent reply	other threads:[~2024-05-03 16:09 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 [this message]
2024-05-07  5:28       ` Zhijian Li (Fujitsu)
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=66350bb1d3817_1aefb294ba@dwillia2-mobl3.amr.corp.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alison.schofield@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=lizhijian@fujitsu.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