Re: [PATCH 31/44] iov_iter: first_{iovec,bvec}_segment() - simplify a bit

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

 



On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> 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@xxxxxxxxxxxxxxxxxx>
> ---
>  lib/iov_iter.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 9ef671b101dc..0bed684d91d0 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -1310,7 +1310,7 @@ static unsigned long found_ubuf_segment(unsigned long addr,
>  					size_t len,
>  					size_t *size, size_t *start)
>  {
> -	len += (*start = addr % PAGE_SIZE);
> +	*start = addr % PAGE_SIZE;
>  	*size = len;
>  	return addr & PAGE_MASK;
>  }
> @@ -1354,7 +1354,7 @@ static struct page *first_bvec_segment(const struct iov_iter *i,
>  		len = maxsize;
>  	skip += i->bvec->bv_offset;
>  	page = i->bvec->bv_page + skip / PAGE_SIZE;
> -	len += (*start = skip % PAGE_SIZE);
> +	*start = skip % PAGE_SIZE;
>  	*size = len;
>  	return page;
>  }
> @@ -1383,9 +1383,9 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,
>  			gup_flags |= FOLL_NOFAULT;
>  
>  		addr = first_iovec_segment(i, &len, start, maxsize);
> -		if (len > maxpages * PAGE_SIZE)
> -			len = maxpages * PAGE_SIZE;
> -		n = DIV_ROUND_UP(len, PAGE_SIZE);
> +		n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
> +		if (n > maxpages)
> +			n = maxpages;
>  		if (!*pages) {
>  			*pages = get_pages_array(n);
>  			if (!*pages)
> @@ -1394,25 +1394,25 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,
>  		res = get_user_pages_fast(addr, n, gup_flags, *pages);
>  		if (unlikely(res <= 0))
>  			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)) {
>  		struct page **p;
>  		struct page *page;
>  
>  		page = first_bvec_segment(i, &len, start, maxsize);
> -		if (len > maxpages * PAGE_SIZE)
> -			len = maxpages * PAGE_SIZE;
> -		n = DIV_ROUND_UP(len, PAGE_SIZE);
> +		n = DIV_ROUND_UP(len + *start, PAGE_SIZE);
> +		if (n > maxpages)
> +			n = maxpages;
>  		p = *pages;
>  		if (!p) {
>  			*pages = p = get_pages_array(n);
>  			if (!p)
>  				return -ENOMEM;
>  		}
> -		while (n--)
> +		for (int k = 0; k < n; k++)
>  			get_page(*p++ = page++);
> -		return len - *start;
> +		return min_t(size_t, len, n * PAGE_SIZE - *start);
>  	}
>  	if (iov_iter_is_pipe(i))
>  		return pipe_get_pages(i, pages, maxsize, maxpages, start);

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