linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: lustre: lov: Fix signed wrap around when decrementing index 'i'
@ 2016-11-10 14:19 Colin King
  2016-11-10 22:31 ` Dilger, Andreas
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2016-11-10 14:19 UTC (permalink / raw)
  To: Andreas Dilger, James Simmons, Greg Kroah-Hartman,
	John L . Hammond, Amitoj Kaur Chawla, lustre-devel, devel
  Cc: linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/lustre/lustre/lov/lov_ea.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_ea.c b/drivers/staging/lustre/lustre/lov/lov_ea.c
index 53db170..399298c 100644
--- a/drivers/staging/lustre/lustre/lov/lov_ea.c
+++ b/drivers/staging/lustre/lustre/lov/lov_ea.c
@@ -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;
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: lustre: lov: Fix signed wrap around when decrementing index 'i'
  2016-11-10 14:19 [PATCH] staging: lustre: lov: Fix signed wrap around when decrementing index 'i' Colin King
@ 2016-11-10 22:31 ` Dilger, Andreas
  0 siblings, 0 replies; 2+ messages in thread
From: Dilger, Andreas @ 2016-11-10 22:31 UTC (permalink / raw)
  To: Colin King
  Cc: James Simmons, Greg Kroah-Hartman, Hammond, John,
	Amitoj Kaur Chawla, lustre-devel, devel, linux-kernel

On Nov 10, 2016, at 07:19, Colin King <colin.king@canonical.com> wrote:
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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

> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/staging/lustre/lustre/lov/lov_ea.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/lustre/lustre/lov/lov_ea.c b/drivers/staging/lustre/lustre/lov/lov_ea.c
> index 53db170..399298c 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_ea.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_ea.c
> @@ -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;
> -- 
> 2.10.2
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-10 22:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-10 14:19 [PATCH] staging: lustre: lov: Fix signed wrap around when decrementing index 'i' Colin King
2016-11-10 22:31 ` Dilger, Andreas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).