Skip to content

Commit 23c560a

Browse files
htejunJens Axboe
authored andcommitted
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 <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 0910697 commit 23c560a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎lib/scatterlist.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,12 @@ bool sg_miter_next(struct sg_mapping_iter *miter)
347347
sg_miter_stop(miter);
348348

349349
/* get to the next sg if necessary. __offset is adjusted by stop */
350-
if (miter->__offset == miter->__sg->length && --miter->__nents) {
351-
miter->__sg = sg_next(miter->__sg);
352-
miter->__offset = 0;
350+
while (miter->__offset == miter->__sg->length) {
351+
if (--miter->__nents) {
352+
miter->__sg = sg_next(miter->__sg);
353+
miter->__offset = 0;
354+
} else
355+
return false;
353356
}
354357

355358
/* map the next page */

0 commit comments

Comments
 (0)