Message ID | 20230531022718.7691-1-lizhijian@fujitsu.com |
---|---|
State | Accepted |
Commit | b36e323b9c2f25ad9867fd6f7ead986418b6d0b3 |
Headers | show |
Series | [ndctl] cxl/region: Fix memdevs leak | expand |
The 05/31/2023 10:27, Li Zhijian wrote: > p.memdevs should be released in error path > > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> > --- Make sense to me. Fan > cxl/region.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/cxl/region.c b/cxl/region.c > index 07ce4a319fd0..7f60094e8b49 100644 > --- a/cxl/region.c > +++ b/cxl/region.c > @@ -300,11 +300,11 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, > if (p->mode == CXL_DECODER_MODE_RAM && param.uuid) { > log_err(&rl, > "can't set UUID for ram / volatile regions"); > - return -EINVAL; > + goto err; > } > if (p->mode == CXL_DECODER_MODE_NONE) { > log_err(&rl, "unsupported type: %s\n", param.type); > - return -EINVAL; > + goto err; > } > } else { > p->mode = CXL_DECODER_MODE_PMEM; > @@ -314,21 +314,21 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, > p->size = parse_size64(param.size); > if (p->size == ULLONG_MAX) { > log_err(&rl, "Invalid size: %s\n", param.size); > - return -EINVAL; > + goto err; > } > } > > if (param.ways <= 0) { > log_err(&rl, "Invalid interleave ways: %d\n", param.ways); > - return -EINVAL; > + goto err; > } else if (param.ways < INT_MAX) { > p->ways = param.ways; > if (!validate_ways(p, count)) > - return -EINVAL; > + goto err; > } else if (count) { > p->ways = count; > if (!validate_ways(p, count)) > - return -EINVAL; > + goto err; > } else > p->ways = p->num_memdevs; > > @@ -336,7 +336,7 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, > if (param.granularity <= 0) { > log_err(&rl, "Invalid interleave granularity: %d\n", > param.granularity); > - return -EINVAL; > + goto err; > } > p->granularity = param.granularity; > } > @@ -346,18 +346,22 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, > log_err(&rl, > "size (%lu) is not an integral multiple of interleave-ways (%u)\n", > p->size, p->ways); > - return -EINVAL; > + goto err; > } > } > > if (param.uuid) { > if (uuid_parse(param.uuid, p->uuid)) { > error("failed to parse uuid: '%s'\n", param.uuid); > - return -EINVAL; > + goto err; > } > } > > return 0; > + > +err: > + json_object_put(p->memdevs); > + return -EINVAL; > } > > static int parse_region_options(int argc, const char **argv, > -- > 2.29.2 >
diff --git a/cxl/region.c b/cxl/region.c index 07ce4a319fd0..7f60094e8b49 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -300,11 +300,11 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, if (p->mode == CXL_DECODER_MODE_RAM && param.uuid) { log_err(&rl, "can't set UUID for ram / volatile regions"); - return -EINVAL; + goto err; } if (p->mode == CXL_DECODER_MODE_NONE) { log_err(&rl, "unsupported type: %s\n", param.type); - return -EINVAL; + goto err; } } else { p->mode = CXL_DECODER_MODE_PMEM; @@ -314,21 +314,21 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, p->size = parse_size64(param.size); if (p->size == ULLONG_MAX) { log_err(&rl, "Invalid size: %s\n", param.size); - return -EINVAL; + goto err; } } if (param.ways <= 0) { log_err(&rl, "Invalid interleave ways: %d\n", param.ways); - return -EINVAL; + goto err; } else if (param.ways < INT_MAX) { p->ways = param.ways; if (!validate_ways(p, count)) - return -EINVAL; + goto err; } else if (count) { p->ways = count; if (!validate_ways(p, count)) - return -EINVAL; + goto err; } else p->ways = p->num_memdevs; @@ -336,7 +336,7 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, if (param.granularity <= 0) { log_err(&rl, "Invalid interleave granularity: %d\n", param.granularity); - return -EINVAL; + goto err; } p->granularity = param.granularity; } @@ -346,18 +346,22 @@ static int parse_create_options(struct cxl_ctx *ctx, int count, log_err(&rl, "size (%lu) is not an integral multiple of interleave-ways (%u)\n", p->size, p->ways); - return -EINVAL; + goto err; } } if (param.uuid) { if (uuid_parse(param.uuid, p->uuid)) { error("failed to parse uuid: '%s'\n", param.uuid); - return -EINVAL; + goto err; } } return 0; + +err: + json_object_put(p->memdevs); + return -EINVAL; } static int parse_region_options(int argc, const char **argv,
p.memdevs should be released in error path Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> --- cxl/region.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)