diff mbox series

[ndctl,1/3] cxl/region: fix a dereferecnce after NULL check

Message ID 20220823072106.398076-2-vishal.l.verma@intel.com (mailing list archive)
State Superseded
Headers show
Series cxl: static analysis fixes | expand

Commit Message

Verma, Vishal L Aug. 23, 2022, 7:21 a.m. UTC
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.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 cxl/region.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Verma, Vishal L Aug. 23, 2022, 7:27 a.m. UTC | #1
On Tue, 2022-08-23 at 01:21 -0600, Vishal Verma wrote:
> 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.
> 
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>  cxl/region.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/cxl/region.c b/cxl/region.c
> index a30313c..9372d6b 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -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.

>                         rc = decoder_region_action(p, decoder, action, count);
>                         if (rc)
>                                 err_rc = rc;
diff mbox series

Patch

diff --git a/cxl/region.c b/cxl/region.c
index a30313c..9372d6b 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -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;