Message ID | 20220622041552.737754-33-viro@zeniv.linux.org.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/44] 9p: handling Rerror without copy_from_iter_full() | expand |
Subject line should read "first_iovec_segment" On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote: > ... and calculate the offset in the caller > > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> > --- > lib/iov_iter.c | 22 +++++++--------------- > 1 file changed, 7 insertions(+), 15 deletions(-) > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index fca66ecce7a0..f455b8ee0d76 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1306,33 +1306,23 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i, > return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); > } > > -static unsigned long found_ubuf_segment(unsigned long addr, size_t *start) > -{ > - *start = addr % PAGE_SIZE; > - return addr & PAGE_MASK; > -} > - > /* must be done on non-empty ITER_UBUF or ITER_IOVEC one */ > static unsigned long first_iovec_segment(const struct iov_iter *i, > - size_t *size, size_t *start) > + size_t *size) > { > size_t skip; > long k; > > - if (iter_is_ubuf(i)) { > - unsigned long addr = (unsigned long)i->ubuf + i->iov_offset; > - return found_ubuf_segment(addr, start); > - } > + if (iter_is_ubuf(i)) > + return (unsigned long)i->ubuf + i->iov_offset; > > for (k = 0, skip = i->iov_offset; k < i->nr_segs; k++, skip = 0) { > - unsigned long addr = (unsigned long)i->iov[k].iov_base + skip; > size_t len = i->iov[k].iov_len - skip; > - > if (unlikely(!len)) > continue; > if (*size > len) > *size = len; > - return found_ubuf_segment(addr, start); > + return (unsigned long)i->iov[k].iov_base + skip; > } > BUG(); // if it had been empty, we wouldn't get called > } > @@ -1375,7 +1365,9 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, > if (i->nofault) > gup_flags |= FOLL_NOFAULT; > > - addr = first_iovec_segment(i, &maxsize, start); > + addr = first_iovec_segment(i, &maxsize); > + *start = addr % PAGE_SIZE; > + addr &= PAGE_MASK; > n = DIV_ROUND_UP(maxsize + *start, PAGE_SIZE); > if (n > maxpages) > n = maxpages; Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff --git a/lib/iov_iter.c b/lib/iov_iter.c index fca66ecce7a0..f455b8ee0d76 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1306,33 +1306,23 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i, return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); } -static unsigned long found_ubuf_segment(unsigned long addr, size_t *start) -{ - *start = addr % PAGE_SIZE; - return addr & PAGE_MASK; -} - /* must be done on non-empty ITER_UBUF or ITER_IOVEC one */ static unsigned long first_iovec_segment(const struct iov_iter *i, - size_t *size, size_t *start) + size_t *size) { size_t skip; long k; - if (iter_is_ubuf(i)) { - unsigned long addr = (unsigned long)i->ubuf + i->iov_offset; - return found_ubuf_segment(addr, start); - } + if (iter_is_ubuf(i)) + return (unsigned long)i->ubuf + i->iov_offset; for (k = 0, skip = i->iov_offset; k < i->nr_segs; k++, skip = 0) { - unsigned long addr = (unsigned long)i->iov[k].iov_base + skip; size_t len = i->iov[k].iov_len - skip; - if (unlikely(!len)) continue; if (*size > len) *size = len; - return found_ubuf_segment(addr, start); + return (unsigned long)i->iov[k].iov_base + skip; } BUG(); // if it had been empty, we wouldn't get called } @@ -1375,7 +1365,9 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, if (i->nofault) gup_flags |= FOLL_NOFAULT; - addr = first_iovec_segment(i, &maxsize, start); + addr = first_iovec_segment(i, &maxsize); + *start = addr % PAGE_SIZE; + addr &= PAGE_MASK; n = DIV_ROUND_UP(maxsize + *start, PAGE_SIZE); if (n > maxpages) n = maxpages;
... and calculate the offset in the caller Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> --- lib/iov_iter.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)