Commit 6a839d30 authored by Andrew Morton's avatar Andrew Morton Committed by David S. Miller

[PATCH] make readv/writev return 0 for 0 segments

Should resolve an ongoing fiasco concerning what we should return to
userspace if they do a readv or writev of zero segments.

SuS is ambiguous, but implies EINVAL.  We're currently returning
EINVAL, but 2.4 returns zero.

I think zero makes more sense, and it is what 2.4 does.
parent 522864f4
...@@ -316,7 +316,7 @@ static ssize_t do_readv_writev(int type, struct file *file, ...@@ -316,7 +316,7 @@ static ssize_t do_readv_writev(int type, struct file *file,
size_t tot_len; size_t tot_len;
struct iovec iovstack[UIO_FASTIOV]; struct iovec iovstack[UIO_FASTIOV];
struct iovec *iov=iovstack; struct iovec *iov=iovstack;
ssize_t ret = -EINVAL; ssize_t ret;
int seg; int seg;
io_fn_t fn; io_fn_t fn;
iov_fn_t fnv; iov_fn_t fnv;
...@@ -325,8 +325,9 @@ static ssize_t do_readv_writev(int type, struct file *file, ...@@ -325,8 +325,9 @@ static ssize_t do_readv_writev(int type, struct file *file,
/* /*
* SuS says "The readv() function *may* fail if the iovcnt argument * SuS says "The readv() function *may* fail if the iovcnt argument
* was less than or equal to 0, or greater than {IOV_MAX}. Linux has * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
* traditionally returned -EINVAL for zero segments, so... * traditionally returned zero for zero segments, so...
*/ */
ret = 0;
if (nr_segs == 0) if (nr_segs == 0)
goto out; goto out;
...@@ -334,6 +335,7 @@ static ssize_t do_readv_writev(int type, struct file *file, ...@@ -334,6 +335,7 @@ static ssize_t do_readv_writev(int type, struct file *file,
* First get the "struct iovec" from user memory and * First get the "struct iovec" from user memory and
* verify all the pointers * verify all the pointers
*/ */
ret = -EINVAL;
if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0)) if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
goto out; goto out;
if (!file->f_op) if (!file->f_op)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment