cxl: static analysis fixes
Vishal Verma
maintainerv2 cover cxl: static analysis fixes
Changes since v1[1]:
- Fix the decoder filter check in patch 1.
- Fix a missed free(path) in patch 2.
[1]: https://lore.kernel.org/linux-cxl/[email protected]
---
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 | 4 +++- cxl/filter.c | 2 +- cxl/region.c | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-)
base-commit: 9a993ce24fdd5de45774b65211570dd514cdf61d
Signature · 1 line
2.37.2
Vishal Verma
maintainerPATCH v2 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(). The NULL check is valid because it was the filter result being checked, however, while doing this, the original 'decoder' variable was being clobbered.
Check the filter results independently of the original decoder variable.
--- cxl/region.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
cxl/region.c +2 -3
@@ -686,9 +686,8 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,continue ; cxl_decoder_foreach (port, decoder) { - decoder =util_cxl_decoder_filter (decoder, - param.root_decoder); -if (!decoder) +if (!util_cxl_decoder_filter (decoder, + param.root_decoder))continue ; rc =decoder_region_action (p, decoder, action, count);if (rc)
Signature · 1 line
2.37.2
RE: [ndctl PATCH v2 1/3] cxl/region: fix a dereferecnce after NULL check
Quoted 18 lines · Vishal Verma
A NULL check in
region_action()implies that 'decoder' might be NULL, but later we dereference it duringcxl_decoder_foreach(). The NULL check is valid because it was the filter result being checked, however, while doing this, the original 'decoder' variable was being clobbered.Check the filter results independently of the original decoder variable.
Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- cxl/region.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)cxl/region.c +0
-0
cxl/region.c static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, · line 691
Quoted 9 lines
cxl/region.c +2
-3@@ -686,9 +686,8 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,continue ; cxl_decoder_foreach (port, decoder) { - decoder =util_cxl_decoder_filter (decoder, - param.root_decoder); -if (!decoder) +if (!util_cxl_decoder_filter (decoder, + param.root_decoder))continue ;
Looks good.
Re: [ndctl PATCH v2 1/3] cxl/region: fix a dereferecnce after NULL check
In reply to Vishal VermaQuoted 9 lines · Vishal Verma
A NULL check in
region_action()implies that 'decoder' might be NULL, but later we dereference it duringcxl_decoder_foreach(). The NULL check is valid because it was the filter result being checked, however, while doing this, the original 'decoder' variable was being clobbered.Check the filter results independently of the original decoder variable.
Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 20 lines
--- cxl/region.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)cxl/region.c +2
-3@@ -686,9 +686,8 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,continue ; cxl_decoder_foreach (port, decoder) { - decoder =util_cxl_decoder_filter (decoder, - param.root_decoder); -if (!decoder) +if (!util_cxl_decoder_filter (decoder, + param.root_decoder))continue ; rc =decoder_region_action (p, decoder, action, count);if (rc)
Re: [ndctl PATCH v2 1/3] cxl/region: fix a dereferecnce after NULL check
In reply to Vishal VermaQuoted 9 lines · On Tue, 23 Aug 2022 01:45:25 -0600 Vishal Verma <[email protected]>…
A NULL check in
region_action()implies that 'decoder' might be NULL, but later we dereference it duringcxl_decoder_foreach(). The NULL check is valid because it was the filter result being checked, however, while doing this, the original 'decoder' variable was being clobbered.Check the filter results independently of the original decoder variable.
Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Typo in patch title.
Quoted 20 lines
--- cxl/region.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)cxl/region.c +2
-3@@ -686,9 +686,8 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,continue ; cxl_decoder_foreach (port, decoder) { - decoder =util_cxl_decoder_filter (decoder, - param.root_decoder); -if (!decoder) +if (!util_cxl_decoder_filter (decoder, + param.root_decoder))continue ; rc =decoder_region_action (p, decoder, action, count);if (rc)
Vishal Verma
maintainerPATCH v2 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.
Add anew error label to just free 'path' and return for this exit case.
--- cxl/lib/libcxl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
cxl/lib/libcxl.c +3 -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; + goto err_path; region->id = id; region->ctx = ctx;
@@ -551,11 +551,13 @@ 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);free (region->dev_buf);free (region); +err_path:free (path);return NULL ; }
Signature · 1 line
2.37.2
RE: [ndctl PATCH v2 2/3] libcxl: fox a resource leak and a forward NULL check
Quoted 6 lines · Vishal Verma
Static 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.Add anew error label to just free 'path' and return for this exit case.
s/anew/a new/
Re: [ndctl PATCH v2 2/3] libcxl: fox a resource leak and a forward NULL check
In reply to Vishal VermaQuoted 9 lines · Vishal Verma
Static 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.Add anew error label to just free 'path' and return for this exit case.
Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 31 lines
--- cxl/lib/libcxl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)cxl/lib/libcxl.c +3
-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; + goto err_path; region->id = id; region->ctx = ctx;@@ -551,11 +551,13 @@ 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);free (region->dev_buf);free (region); +err_path:free (path);return NULL ; }
Vishal Verma
maintainerPATCH v2 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
RE: [ndctl PATCH v2 3/3] cxl/filter: Fix an uninitialized pointer dereference
Quoted 15 lines · Vishal Verma
Static 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.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- cxl/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)cxl/filter.c +0
-0
cxl/filter.c static void walk_decoders(struct cxl_port *port, struct cxl_filter_params *p, · line 799
Quoted 5 lines
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 ;
Looks good,
Re: [ndctl PATCH v2 3/3] cxl/filter: Fix an uninitialized pointer dereference
In reply to Vishal VermaQuoted 6 lines · Vishal Verma
Static 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.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 17 lines
--- 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;
Quoted 5 lines · On Tue, 23 Aug 2022 01:45:24 -0600 Vishal Verma <[email protected]>…
Changes since v1[1]:
- Fix the decoder filter check in patch 1.
- Fix a missed free(path) in patch 2.
FWIW: Series looks fine to me.
Quoted 18 lines
---
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 dereferencecxl/lib/libcxl.c | 4 +++- cxl/filter.c | 2 +- cxl/region.c | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-)base-commit:
9a993ce24fdd5de45774b65211570dd514cdf61d