cxl: static analysis fixes
Vishal Verma
maintainercover cxl: static analysis fixes
Fix a small handful of issues reported by scan.coverity.com for the recent region management additions.
Vishal Verma (3):
cxl/region: fix a dereferecnce after NULL check
libcxl: fox a resource leak and a forward NULL check cxl/filter: Fix an uninitialized pointer dereference
cxl/lib/libcxl.c | 3 ++- cxl/filter.c | 2 +- cxl/region.c | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-)
base-commit: 9a993ce24fdd5de45774b65211570dd514cdf61d
Signature · 1 line
2.37.2
Vishal Verma
maintainerPATCH 1/3 cxl/region: fix a dereferecnce after NULL check
A NULL check in region_action() implies that 'decoder' might be NULL, but later we dereference it during cxl_decoder_foreach().
Since cxl_decoder_foreach() won't ever enter the loop with a NULL decoder, the check was superfluous. Remove it.
--- cxl/region.c | 2 -- 1 file changed, 2 deletions(-)
cxl/region.c +0 -2
@@ -688,8 +688,6 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, cxl_decoder_foreach (port, decoder) { decoder =util_cxl_decoder_filter (decoder, param.root_decoder); -if (!decoder) -continue ; rc =decoder_region_action (p, decoder, action, count);if (rc) err_rc = rc;
Signature · 1 line
2.37.2
Verma, Vishal L
maintainerRe: [ndctl PATCH 1/3] cxl/region: fix a dereferecnce after NULL check
Quoted 17 lines · Vishal Verma
A NULL check in
region_action()implies that 'decoder' might be NULL, but later we dereference it duringcxl_decoder_foreach().Since
cxl_decoder_foreach()won't ever enter the loop with a NULL decoder, the check was superfluous. Remove it.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
cxl/region.c | 2 --1 file changed, 2 deletions(-)cxl/region.c +0
-0
cxl/region.c static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, · line 692
Quoted 5 lines
cxl/region.c +0
-2@@ -688,8 +688,6 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, cxl_decoder_foreach (port, decoder) { decoder = util_cxl_decoder_filter(decoder, param.root_decoder); - if (!decoder) - continue;
Hm, this is actually wrong. We need to save the filter results in a new variable, and NULL check that, while keeping the original 'decoder' variable intact for the loop. I'll send v2.
Quoted 3 lines
cxl/region.c +0
-0rc = decoder_region_action(p, decoder, action, count); if (rc) err_rc = rc;
Vishal Verma
maintainerPATCH 2/3 libcxl: fox a resource leak and a forward NULL check
In reply to Vishal VermaStatic analysis reports a couple of issues in add_cxl_region(). Firstly, 'path' wasn't freed in the success case, only in the error case. Secondly, the error handling after 'calloc()'ing the region object erroneously jumped to the error path which tried to free the region object, instead of directly returning NULL.
--- cxl/lib/libcxl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cxl/lib/libcxl.c +2 -1
@@ -482,7 +482,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base) region =calloc (1 ,sizeof (*region));if (!region) - goto err; +return NULL ; region->id = id; region->ctx = ctx;
@@ -551,6 +551,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)list_add_sorted (&decoder->regions, region, list, region_start_cmp); +free (path);return region; err:free (region->dev_path);
Signature · 1 line
2.37.2
Vishal Verma
maintainerPATCH 3/3 cxl/filter: Fix an uninitialized pointer dereference
In reply to Vishal VermaStatic analysis points out that there was a chance that 'jdecoder' could be used while uninitialized in walk_decoders(). Initialize it to NULL to avoid this.
--- cxl/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cxl/filter.c +1 -1
@@ -796,7 +796,7 @@ static void walk_decoders(struct cxl_port *port, struct cxl_filter_params *p, cxl_decoder_foreach(port, decoder) {const char *devname =cxl_decoder_get_devname (decoder);struct json_object *jchildregions =NULL ; -struct json_object *jdecoder; +struct json_object *jdecoder =NULL ;if (!p->decoders) goto walk_children;
Signature · 1 line
2.37.2