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: 6e09926418
("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>
This commit is contained in:
parent
d555105271
commit
49ba7b515c
@ -2352,15 +2352,6 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
|
|||||||
struct device *dev;
|
struct device *dev;
|
||||||
int rc;
|
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);
|
cxlr = cxl_region_alloc(cxlrd, id);
|
||||||
if (IS_ERR(cxlr))
|
if (IS_ERR(cxlr))
|
||||||
return cxlr;
|
return cxlr;
|
||||||
@ -2415,6 +2406,15 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
|
|||||||
{
|
{
|
||||||
int rc;
|
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);
|
rc = memregion_alloc(GFP_KERNEL);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return ERR_PTR(rc);
|
return ERR_PTR(rc);
|
||||||
|
Loading…
Reference in New Issue
Block a user