Skip to content

Commit

Permalink
scatterlist: make sure sg_miter_next() doesn't return 0 sized mappings
Browse files Browse the repository at this point in the history
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 <tj@kernel.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Tejun Heo authored and Jens Axboe committed Apr 22, 2009
1 parent 0910697 commit 23c560a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/scatterlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 23c560a

Please sign in to comment.