On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote: > do what we do for iovec/kvec; that ends up generating better code, > AFAICS. > > Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx> > --- > lib/iov_iter.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 8275b28e886b..93ceb13ec7b5 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -870,17 +870,22 @@ static void pipe_advance(struct iov_iter *i, size_t size) > > static void iov_iter_bvec_advance(struct iov_iter *i, size_t size) > { > - struct bvec_iter bi; > + const struct bio_vec *bvec, *end; > > - bi.bi_size = i->count; > - bi.bi_bvec_done = i->iov_offset; > - bi.bi_idx = 0; > - bvec_iter_advance(i->bvec, &bi, size); > + if (!i->count) > + return; > + i->count -= size; > + > + size += i->iov_offset; > > - i->bvec += bi.bi_idx; > - i->nr_segs -= bi.bi_idx; > - i->count = bi.bi_size; > - i->iov_offset = bi.bi_bvec_done; > + for (bvec = i->bvec, end = bvec + i->nr_segs; bvec < end; bvec++) { > + if (likely(size < bvec->bv_len)) > + break; > + size -= bvec->bv_len; > + } > + i->iov_offset = size; > + i->nr_segs -= bvec - i->bvec; > + i->bvec = bvec; > } > > static void iov_iter_iovec_advance(struct iov_iter *i, size_t size) Much simpler to follow, IMO... Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>