2024-05-07 05:35:12

by Li Zhijian

[permalink] [raw]
Subject: [PATCH v2] 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: 6e099264185d ("cxl/region: Add volatile region creation support")
Signed-off-by: Li Zhijian <[email protected]>
---
V2: Move the mode verification to __create_region() # Dan
---
drivers/cxl/core/region.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 812b2948b6c6..18b95149640b 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);
--
2.29.2



2024-05-21 07:27:25

by Li Zhijian

[permalink] [raw]
Subject: Re: [PATCH v2] cxl/region: Fix memregion leaks in devm_cxl_add_region()

ping


On 07/05/2024 13:34, Li Zhijian wrote:
> Move the mode verification to __create_region() before allocating the
> memregion to avoid the memregion leaks.
>
> Fixes: 6e099264185d ("cxl/region: Add volatile region creation support")
> Signed-off-by: Li Zhijian <[email protected]>
> ---
> V2: Move the mode verification to __create_region() # Dan
> ---
> drivers/cxl/core/region.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 812b2948b6c6..18b95149640b 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);

2024-05-21 16:20:08

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH v2] cxl/region: Fix memregion leaks in devm_cxl_add_region()

Li Zhijian wrote:
> Move the mode verification to __create_region() before allocating the
> memregion to avoid the memregion leaks.
>
> Fixes: 6e099264185d ("cxl/region: Add volatile region creation support")
> Signed-off-by: Li Zhijian <[email protected]>
> ---
> V2: Move the mode verification to __create_region() # Dan
> ---
> drivers/cxl/core/region.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)

LGTM

Reviewed-by: Dan Williams <[email protected]>