Skip to contentSkip to conversation

btt_check_arenas: fix use of uninitialized variable

PATCH In review Jeff Moyer 2 participants 2 messages Oct 16, 2017 – Oct 31, 2017 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 btt_check_arenas: fix use of uninitialized variable

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.

ndctl/check.c +3 -2
index 915bb9d..93f95c6 100644
@@ -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
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jeff Moyer

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.

Good catch!

Quoted 18 lines
ndctl/check.c +3 -2
index 915bb9d..93f95c6 100644
@@ -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;
 }
 
Quoted 4 lines

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm