diff mbox series

[25/44] iov_iter_get_pages(): sanity-check arguments

Message ID 20220622041552.737754-25-viro@zeniv.linux.org.uk (mailing list archive)
State New, archived
Headers show
Series [01/44] 9p: handling Rerror without copy_from_iter_full() | expand

Commit Message

Al Viro June 22, 2022, 4:15 a.m. UTC
zero maxpages is bogus, but best treated as "just return 0";
NULL pages, OTOH, should be treated as a hard bug.

get rid of now completely useless checks in xarray_get_pages{,_alloc}().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 lib/iov_iter.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Jeff Layton June 28, 2022, 11:47 a.m. UTC | #1
On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> zero maxpages is bogus, but best treated as "just return 0";
> NULL pages, OTOH, should be treated as a hard bug.
> 
> get rid of now completely useless checks in xarray_get_pages{,_alloc}().
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  lib/iov_iter.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 9c25661684c6..5c985cf2858e 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -1271,9 +1271,6 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i,
>  	size_t size = maxsize;
>  	loff_t pos;
>  
> -	if (!size || !maxpages)
> -		return 0;
> -
>  	pos = i->xarray_start + i->iov_offset;
>  	index = pos >> PAGE_SHIFT;
>  	offset = pos & ~PAGE_MASK;
> @@ -1365,10 +1362,11 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,
>  
>  	if (maxsize > i->count)
>  		maxsize = i->count;
> -	if (!maxsize)
> +	if (!maxsize || !maxpages)
>  		return 0;
>  	if (maxsize > MAX_RW_COUNT)
>  		maxsize = MAX_RW_COUNT;
> +	BUG_ON(!pages);
>  
>  	if (likely(user_backed_iter(i))) {
>  		unsigned int gup_flags = 0;
> @@ -1441,9 +1439,6 @@ static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i,
>  	size_t size = maxsize;
>  	loff_t pos;
>  
> -	if (!size)
> -		return 0;
> -
>  	pos = i->xarray_start + i->iov_offset;
>  	index = pos >> PAGE_SHIFT;
>  	offset = pos & ~PAGE_MASK;

Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 9c25661684c6..5c985cf2858e 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1271,9 +1271,6 @@  static ssize_t iter_xarray_get_pages(struct iov_iter *i,
 	size_t size = maxsize;
 	loff_t pos;
 
-	if (!size || !maxpages)
-		return 0;
-
 	pos = i->xarray_start + i->iov_offset;
 	index = pos >> PAGE_SHIFT;
 	offset = pos & ~PAGE_MASK;
@@ -1365,10 +1362,11 @@  ssize_t iov_iter_get_pages(struct iov_iter *i,
 
 	if (maxsize > i->count)
 		maxsize = i->count;
-	if (!maxsize)
+	if (!maxsize || !maxpages)
 		return 0;
 	if (maxsize > MAX_RW_COUNT)
 		maxsize = MAX_RW_COUNT;
+	BUG_ON(!pages);
 
 	if (likely(user_backed_iter(i))) {
 		unsigned int gup_flags = 0;
@@ -1441,9 +1439,6 @@  static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i,
 	size_t size = maxsize;
 	loff_t pos;
 
-	if (!size)
-		return 0;
-
 	pos = i->xarray_start + i->iov_offset;
 	index = pos >> PAGE_SHIFT;
 	offset = pos & ~PAGE_MASK;