1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-26 18:43:33 -05:00

first_iovec_segment(): just return address

... and calculate the offset in the caller

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2022-06-17 16:07:49 -04:00
parent 59dbd7d090
commit dd45ab9dd2

View file

@ -1293,22 +1293,19 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i,
} }
/* must be done on non-empty ITER_IOVEC one */ /* must be done on non-empty ITER_IOVEC one */
static unsigned long first_iovec_segment(const struct iov_iter *i, static unsigned long first_iovec_segment(const struct iov_iter *i, size_t *size)
size_t *size, size_t *start)
{ {
size_t skip; size_t skip;
long k; long k;
for (k = 0, skip = i->iov_offset; k < i->nr_segs; k++, skip = 0) { 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; size_t len = i->iov[k].iov_len - skip;
if (unlikely(!len)) if (unlikely(!len))
continue; continue;
if (*size > len) if (*size > len)
*size = len; *size = len;
*start = addr % PAGE_SIZE; return (unsigned long)i->iov[k].iov_base + skip;
return addr & PAGE_MASK;
} }
BUG(); // if it had been empty, we wouldn't get called BUG(); // if it had been empty, we wouldn't get called
} }
@ -1351,7 +1348,9 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,
if (i->nofault) if (i->nofault)
gup_flags |= FOLL_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); n = DIV_ROUND_UP(maxsize + *start, PAGE_SIZE);
if (n > maxpages) if (n > maxpages)
n = maxpages; n = maxpages;
@ -1482,7 +1481,9 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
if (i->nofault) if (i->nofault)
gup_flags |= FOLL_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); n = DIV_ROUND_UP(maxsize + *start, PAGE_SIZE);
p = get_pages_array(n); p = get_pages_array(n);
if (!p) if (!p)