iov_iter: first_{iovec,bvec}_segment() - simplify a bit
We return length + offset in page via *size. Don't bother - the caller can do that arithmetics just as well; just report the length to it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Родитель
599a0bdd72
Коммит
dda8e5d17c
|
@ -1308,7 +1308,7 @@ static unsigned long first_iovec_segment(const struct iov_iter *i,
|
||||||
continue;
|
continue;
|
||||||
if (len > maxsize)
|
if (len > maxsize)
|
||||||
len = maxsize;
|
len = maxsize;
|
||||||
len += (*start = addr % PAGE_SIZE);
|
*start = addr % PAGE_SIZE;
|
||||||
*size = len;
|
*size = len;
|
||||||
return addr & PAGE_MASK;
|
return addr & PAGE_MASK;
|
||||||
}
|
}
|
||||||
|
@ -1328,7 +1328,7 @@ static struct page *first_bvec_segment(const struct iov_iter *i,
|
||||||
len = maxsize;
|
len = maxsize;
|
||||||
skip += i->bvec->bv_offset;
|
skip += i->bvec->bv_offset;
|
||||||
page = i->bvec->bv_page + skip / PAGE_SIZE;
|
page = i->bvec->bv_page + skip / PAGE_SIZE;
|
||||||
len += (*start = skip % PAGE_SIZE);
|
*start = skip % PAGE_SIZE;
|
||||||
*size = len;
|
*size = len;
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -1357,24 +1357,24 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,
|
||||||
gup_flags |= FOLL_NOFAULT;
|
gup_flags |= FOLL_NOFAULT;
|
||||||
|
|
||||||
addr = first_iovec_segment(i, &len, start, maxsize);
|
addr = first_iovec_segment(i, &len, start, maxsize);
|
||||||
if (len > maxpages * PAGE_SIZE)
|
n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
|
||||||
len = maxpages * PAGE_SIZE;
|
if (n > maxpages)
|
||||||
n = DIV_ROUND_UP(len, PAGE_SIZE);
|
n = maxpages;
|
||||||
res = get_user_pages_fast(addr, n, gup_flags, pages);
|
res = get_user_pages_fast(addr, n, gup_flags, pages);
|
||||||
if (unlikely(res <= 0))
|
if (unlikely(res <= 0))
|
||||||
return res;
|
return res;
|
||||||
return (res == n ? len : res * PAGE_SIZE) - *start;
|
return min_t(size_t, len, res * PAGE_SIZE - *start);
|
||||||
}
|
}
|
||||||
if (iov_iter_is_bvec(i)) {
|
if (iov_iter_is_bvec(i)) {
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
page = first_bvec_segment(i, &len, start, maxsize);
|
page = first_bvec_segment(i, &len, start, maxsize);
|
||||||
if (len > maxpages * PAGE_SIZE)
|
n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
|
||||||
len = maxpages * PAGE_SIZE;
|
if (n > maxpages)
|
||||||
n = DIV_ROUND_UP(len, PAGE_SIZE);
|
n = maxpages;
|
||||||
while (n--)
|
for (int k = 0; k < n; k++)
|
||||||
get_page(*pages++ = page++);
|
get_page(*pages++ = page++);
|
||||||
return len - *start;
|
return min_t(size_t, len, n * PAGE_SIZE - *start);
|
||||||
}
|
}
|
||||||
if (iov_iter_is_pipe(i))
|
if (iov_iter_is_pipe(i))
|
||||||
return pipe_get_pages(i, pages, maxsize, maxpages, start);
|
return pipe_get_pages(i, pages, maxsize, maxpages, start);
|
||||||
|
@ -1489,7 +1489,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
|
||||||
gup_flags |= FOLL_NOFAULT;
|
gup_flags |= FOLL_NOFAULT;
|
||||||
|
|
||||||
addr = first_iovec_segment(i, &len, start, maxsize);
|
addr = first_iovec_segment(i, &len, start, maxsize);
|
||||||
n = DIV_ROUND_UP(len, PAGE_SIZE);
|
n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
|
||||||
p = get_pages_array(n);
|
p = get_pages_array(n);
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -1500,19 +1500,19 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
*pages = p;
|
*pages = p;
|
||||||
return (res == n ? len : res * PAGE_SIZE) - *start;
|
return min_t(size_t, len, res * PAGE_SIZE - *start);
|
||||||
}
|
}
|
||||||
if (iov_iter_is_bvec(i)) {
|
if (iov_iter_is_bvec(i)) {
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
page = first_bvec_segment(i, &len, start, maxsize);
|
page = first_bvec_segment(i, &len, start, maxsize);
|
||||||
n = DIV_ROUND_UP(len, PAGE_SIZE);
|
n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
|
||||||
*pages = p = get_pages_array(n);
|
*pages = p = get_pages_array(n);
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
while (n--)
|
for (int k = 0; k < n; k++)
|
||||||
get_page(*p++ = page++);
|
get_page(*p++ = page++);
|
||||||
return len - *start;
|
return min_t(size_t, len, n * PAGE_SIZE - *start);
|
||||||
}
|
}
|
||||||
if (iov_iter_is_pipe(i))
|
if (iov_iter_is_pipe(i))
|
||||||
return pipe_get_pages_alloc(i, pages, maxsize, start);
|
return pipe_get_pages_alloc(i, pages, maxsize, start);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче