Skip to contentSkip to conversation

staging: lustre: lov: Fix signed wrap around when decrementing index 'i'

PATCH In review Colin King 2 participants 2 messages Nov 10, 2016 Staging

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 staging: lustre: lov: Fix signed wrap around when decrementing index 'i'

From: Colin Ian King <[email protected]>

Change predecrement compare to post decrement compare to avoid an unsigned integer wrap-around comparisomn when decrementing in the while loop.

Issue found with static analysis with CoverityScan, CID 1375917

---
 drivers/staging/lustre/lustre/lov/lov_ea.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/lov/lov_ea.c +1 -1
index 53db170..399298c 100644
@@ -102,7 +102,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count)
 	return lsm;
 
 err:
-	while (--i >= 0)
+	while (i-- > 0)
 		kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]);
 	kvfree(lsm);
 	return NULL;
Signature · 1 line
2.10.2
#1 lore raw
Quoted 8 lines · Colin King

From: Colin Ian King <[email protected]>

Change predecrement compare to post decrement compare to avoid an unsigned integer wrap-around comparisomn when decrementing in the while loop.

Issue found with static analysis with CoverityScan, CID 1375917

Thanks for the patch. Seems this change has gotten a lot of attention, this is the third patch to the list to fix it. My preference is to undo the int->unsigned declaration change, for which James has already submitted a patch.

Cheers, Andreas

Quoted 21 lines

---
drivers/staging/lustre/lustre/lov/lov_ea.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/lov/lov_ea.c +0 -0
index 53db170..399298c 100644
@@ -102,7 +102,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count)
 	return lsm;
 

err:

drivers/staging/lustre/lustre/lov/lov_ea.c +1 -1
-	while (--i >= 0)
+	while (i-- > 0)
		kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]);
	kvfree(lsm);
	return NULL;
Signature · 1 line
2.10.2