Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 49ba7b5

Browse files
zhijianli88davejiang
authored andcommitted
cxl/region: Fix memregion leaks in devm_cxl_add_region()
Move the mode verification to __create_region() before allocating the memregion to avoid the memregion leaks. Fixes: 6e09926 ("cxl/region: Add volatile region creation support") Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Link: https://lore.kernel.org/r/20240507053421.456439-1-lizhijian@fujitsu.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent d555105 commit 49ba7b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/cxl/core/region.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,15 +2352,6 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
23522352
struct device *dev;
23532353
int rc;
23542354

2355-
switch (mode) {
2356-
case CXL_DECODER_RAM:
2357-
case CXL_DECODER_PMEM:
2358-
break;
2359-
default:
2360-
dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
2361-
return ERR_PTR(-EINVAL);
2362-
}
2363-
23642355
cxlr = cxl_region_alloc(cxlrd, id);
23652356
if (IS_ERR(cxlr))
23662357
return cxlr;
@@ -2415,6 +2406,15 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
24152406
{
24162407
int rc;
24172408

2409+
switch (mode) {
2410+
case CXL_DECODER_RAM:
2411+
case CXL_DECODER_PMEM:
2412+
break;
2413+
default:
2414+
dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
2415+
return ERR_PTR(-EINVAL);
2416+
}
2417+
24182418
rc = memregion_alloc(GFP_KERNEL);
24192419
if (rc < 0)
24202420
return ERR_PTR(rc);

0 commit comments

Comments
 (0)