On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote: > now that we are advancing the iterator, there's no need to > treat the first page separately - just call append_pipe() > in a loop. > > Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx> > --- > lib/iov_iter.c | 36 ++++++++---------------------------- > 1 file changed, 8 insertions(+), 28 deletions(-) > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 70736b3e07c5..a8045c97b975 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1207,10 +1207,10 @@ static ssize_t pipe_get_pages(struct iov_iter *i, > struct page ***pages, size_t maxsize, unsigned maxpages, > size_t *start) > { > - struct pipe_inode_info *pipe = i->pipe; > - unsigned int npages, off, count; > + unsigned int npages, count; > struct page **p; > ssize_t left; > + size_t off; > > if (!sanity(i)) > return -EFAULT; > @@ -1222,38 +1222,18 @@ static ssize_t pipe_get_pages(struct iov_iter *i, > if (!count) > return -ENOMEM; > p = *pages; > - left = maxsize; > - npages = 0; > - if (off) { > - struct pipe_buffer *buf = pipe_buf(pipe, pipe->head - 1); > - > - get_page(*p++ = buf->page); > - left -= PAGE_SIZE - off; > - if (left <= 0) { > - buf->len += maxsize; > - iov_iter_advance(i, maxsize); > - return maxsize; > - } > - buf->len = PAGE_SIZE; > - npages = 1; > - } > - for ( ; npages < count; npages++) { > - struct page *page; > - unsigned int size = min_t(ssize_t, left, PAGE_SIZE); > - > - if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) > - break; > - page = push_anon(pipe, size); > + for (npages = 0, left = maxsize ; npages < count; npages++) { > + struct page *page = append_pipe(i, left, &off); > if (!page) > break; > get_page(*p++ = page); > - left -= size; > + if (left <= PAGE_SIZE - off) > + return maxsize; > + left -= PAGE_SIZE - off; > } > if (!npages) > return -EFAULT; > - maxsize -= left; > - iov_iter_advance(i, maxsize); > - return maxsize; > + return maxsize - left; > } > > static ssize_t iter_xarray_populate_pages(struct page **pages, struct xarray *xa, Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>