Skip to contentSkip to conversation

btt_check_bitmap: initialize rc

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

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 btt_check_bitmap: initialize rc

It may be possible that rc is never set before returning from the function. nfree would have to be zero, and the bitmap would have to be full. Fix it.

ndctl/check.c +1 -2
index 915bb9d..dafd6a8 100644
@@ -508,7 +508,7 @@ static int btt_check_bitmap(struct arena_info *a)
 {
 	unsigned long *bm;
 	u32 i, btt_mapping;
-	int rc;
+	int rc = BTT_BITMAP_ERROR;
 
 	bm = bitmap_alloc(a->internal_nlba);
 	if (bm == NULL)
@@ -521,7 +521,6 @@ static int btt_check_bitmap(struct arena_info *a)
 			info(a->bttc,
 				"arena %d: internal block %#x is referenced by two map entries\n",
 				a->num, btt_mapping);
-			rc = BTT_BITMAP_ERROR;
 			goto out;
 		}
 		bitmap_set(bm, btt_mapping, 1);

_______________________________________________
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 5 lines · Jeff Moyer

It may be possible that rc is never set before returning from the function. nfree would have to be zero, and the bitmap would have to be full. Fix it.

Ah so it shouldn't ever happen in practice, but I can see how a static checker may complain about it. The patch looks good to me.

Quoted 22 lines
ndctl/check.c +1 -2
index 915bb9d..dafd6a8 100644
@@ -508,7 +508,7 @@ static int btt_check_bitmap(struct arena_info *a)
 {
 	unsigned long *bm;
 	u32 i, btt_mapping;
-	int rc;
+	int rc = BTT_BITMAP_ERROR;
 
 	bm = bitmap_alloc(a->internal_nlba);
 	if (bm == NULL)
@@ -521,7 +521,6 @@ static int btt_check_bitmap(struct arena_info *a)
 			info(a->bttc,
 				"arena %d: internal block %#x is referenced by two map entries\n",
 				a->num, btt_mapping);
-			rc = BTT_BITMAP_ERROR;
 			goto out;
 		}
 		bitmap_set(bm, btt_mapping, 1);
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