From 23c560a99d78bddf5c251bfa97bce19e4da4b3f3 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Wed, 15 Apr 2009 22:10:23 +0900 Subject: scatterlist: make sure sg_miter_next() doesn't return 0 sized mappings Impact: fix not-so-critical but annoying bug sg_miter_next() returns 0 sized mapping if there is an zero sized sg entry in the list or at the end of each iteration. As the users always check the ->length field, this bug shouldn't be critical other than causing unnecessary iteration. Fix it. Signed-off-by: Tejun Heo Signed-off-by: Jens Axboe --- lib/scatterlist.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/scatterlist.c b/lib/scatterlist.c index b7b449dafbe5..a295e404e908 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -347,9 +347,12 @@ bool sg_miter_next(struct sg_mapping_iter *miter) sg_miter_stop(miter); /* get to the next sg if necessary. __offset is adjusted by stop */ - if (miter->__offset == miter->__sg->length && --miter->__nents) { - miter->__sg = sg_next(miter->__sg); - miter->__offset = 0; + while (miter->__offset == miter->__sg->length) { + if (--miter->__nents) { + miter->__sg = sg_next(miter->__sg); + miter->__offset = 0; + } else + return false; } /* map the next page */ -- cgit v1.2.3-59-g8ed1b