diff mbox

[ndctl] btt_check_arenas: fix use of uninitialized variable

Message ID x49376ikhuy.fsf@segfault.boston.devel.redhat.com (mailing list archive)
State Accepted
Commit 68dc64b17a63
Headers show

Commit Message

Jeff Moyer Oct. 16, 2017, 7:33 p.m. UTC
Coverity complains that rc, passed to btt_xlat_status, may be
used uninitialized.  In that case, we may also dereference a
NULL pointer.  Fix it by only calling btt_xlat_status with a
valid arena.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

Comments

Verma, Vishal L Oct. 31, 2017, 7:20 p.m. UTC | #1
On 10/16, Jeff Moyer wrote:
> Coverity complains that rc, passed to btt_xlat_status, may be
> used uninitialized.  In that case, we may also dereference a
> NULL pointer.  Fix it by only calling btt_xlat_status with a
> valid arena.
> 
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

Good catch!
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
> 
> diff --git a/ndctl/check.c b/ndctl/check.c
> index 915bb9d..93f95c6 100644
> --- a/ndctl/check.c
> +++ b/ndctl/check.c
> @@ -582,9 +582,10 @@ static int btt_check_arenas(struct btt_chk *bttc)
>  			break;
>  	}
>  
> -	btt_xlat_status(a, rc);
> -	if (rc)
> +	if (a && rc != BTT_OK) {
> +		btt_xlat_status(a, rc);
>  		return -ENXIO;
> +	}
>  	return 0;
>  }
>  
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm
diff mbox

Patch

diff --git a/ndctl/check.c b/ndctl/check.c
index 915bb9d..93f95c6 100644
--- a/ndctl/check.c
+++ b/ndctl/check.c
@@ -582,9 +582,10 @@  static int btt_check_arenas(struct btt_chk *bttc)
 			break;
 	}
 
-	btt_xlat_status(a, rc);
-	if (rc)
+	if (a && rc != BTT_OK) {
+		btt_xlat_status(a, rc);
 		return -ENXIO;
+	}
 	return 0;
 }