Skip to content

Commit

Permalink
Merge tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/g…
Browse files Browse the repository at this point in the history
…it/viro/vfs

Pull iov_iter fix from Al Viro:
 "ITER_XARRAY get_pages fix; now the return value is a lot saner (and
  more similar to logics for other flavours)"

* tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  iov_iter: Fix iter_xarray_get_pages{,_alloc}()
  • Loading branch information
torvalds committed Jun 10, 2022
2 parents a32e7ea + 6c77676 commit b098915
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions lib/iov_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i,
{
unsigned nr, offset;
pgoff_t index, count;
size_t size = maxsize, actual;
size_t size = maxsize;
loff_t pos;

if (!size || !maxpages)
Expand All @@ -1461,13 +1461,7 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i,
if (nr == 0)
return 0;

actual = PAGE_SIZE * nr;
actual -= offset;
if (nr == count && size > 0) {
unsigned last_offset = (nr > 1) ? 0 : offset;
actual -= PAGE_SIZE - (last_offset + size);
}
return actual;
return min(nr * PAGE_SIZE - offset, maxsize);
}

/* must be done on non-empty ITER_IOVEC one */
Expand Down Expand Up @@ -1602,7 +1596,7 @@ static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i,
struct page **p;
unsigned nr, offset;
pgoff_t index, count;
size_t size = maxsize, actual;
size_t size = maxsize;
loff_t pos;

if (!size)
Expand Down Expand Up @@ -1631,13 +1625,7 @@ static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i,
if (nr == 0)
return 0;

actual = PAGE_SIZE * nr;
actual -= offset;
if (nr == count && size > 0) {
unsigned last_offset = (nr > 1) ? 0 : offset;
actual -= PAGE_SIZE - (last_offset + size);
}
return actual;
return min(nr * PAGE_SIZE - offset, maxsize);
}

ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
Expand Down

0 comments on commit b098915

Please sign in to comment.