Re: [PATCH 30/44] iov_iter: lift dealing with maxpages out of first_{iovec,bvec}_segment()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> ---
>  lib/iov_iter.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 92a566f839f9..9ef671b101dc 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -1308,12 +1308,9 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i,
>  
>  static unsigned long found_ubuf_segment(unsigned long addr,
>  					size_t len,
> -					size_t *size, size_t *start,
> -					unsigned maxpages)
> +					size_t *size, size_t *start)
>  {
>  	len += (*start = addr % PAGE_SIZE);
> -	if (len > maxpages * PAGE_SIZE)
> -		len = maxpages * PAGE_SIZE;
>  	*size = len;
>  	return addr & PAGE_MASK;
>  }
> @@ -1321,14 +1318,14 @@ static unsigned long found_ubuf_segment(unsigned long addr,
>  /* 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 maxsize, unsigned maxpages)
> +					 size_t maxsize)
>  {
>  	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, maxsize, size, start, maxpages);
> +		return found_ubuf_segment(addr, maxsize, size, start);
>  	}
>  
>  	for (k = 0, skip = i->iov_offset; k < i->nr_segs; k++, skip = 0) {
> @@ -1339,7 +1336,7 @@ static unsigned long first_iovec_segment(const struct iov_iter *i,
>  			continue;
>  		if (len > maxsize)
>  			len = maxsize;
> -		return found_ubuf_segment(addr, len, size, start, maxpages);
> +		return found_ubuf_segment(addr, len, size, start);
>  	}
>  	BUG(); // if it had been empty, we wouldn't get called
>  }
> @@ -1347,7 +1344,7 @@ static unsigned long first_iovec_segment(const struct iov_iter *i,
>  /* must be done on non-empty ITER_BVEC one */
>  static struct page *first_bvec_segment(const struct iov_iter *i,
>  				       size_t *size, size_t *start,
> -				       size_t maxsize, unsigned maxpages)
> +				       size_t maxsize)
>  {
>  	struct page *page;
>  	size_t skip = i->iov_offset, len;
> @@ -1358,8 +1355,6 @@ static struct page *first_bvec_segment(const struct iov_iter *i,
>  	skip += i->bvec->bv_offset;
>  	page = i->bvec->bv_page + skip / PAGE_SIZE;
>  	len += (*start = skip % PAGE_SIZE);
> -	if (len > maxpages * PAGE_SIZE)
> -		len = maxpages * PAGE_SIZE;
>  	*size = len;
>  	return page;
>  }
> @@ -1387,7 +1382,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, &len, start, maxsize, maxpages);
> +		addr = first_iovec_segment(i, &len, start, maxsize);
> +		if (len > maxpages * PAGE_SIZE)
> +			len = maxpages * PAGE_SIZE;
>  		n = DIV_ROUND_UP(len, PAGE_SIZE);
>  		if (!*pages) {
>  			*pages = get_pages_array(n);
> @@ -1403,7 +1400,9 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,
>  		struct page **p;
>  		struct page *page;
>  
> -		page = first_bvec_segment(i, &len, start, maxsize, maxpages);
> +		page = first_bvec_segment(i, &len, start, maxsize);
> +		if (len > maxpages * PAGE_SIZE)
> +			len = maxpages * PAGE_SIZE;
>  		n = DIV_ROUND_UP(len, PAGE_SIZE);
>  		p = *pages;
>  		if (!p) {

Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux