Commit edab5fe3 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

fs: move more code into do_iter_read/do_iter_write

The checks for the permissions and can read / write flags are common
for the callers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 19c73586
...@@ -922,6 +922,11 @@ static ssize_t do_iter_read(struct file *file, struct iov_iter *iter, ...@@ -922,6 +922,11 @@ static ssize_t do_iter_read(struct file *file, struct iov_iter *iter,
size_t tot_len; size_t tot_len;
ssize_t ret = 0; ssize_t ret = 0;
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
return -EINVAL;
tot_len = iov_iter_count(iter); tot_len = iov_iter_count(iter);
if (!tot_len) if (!tot_len)
goto out; goto out;
...@@ -945,6 +950,11 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, ...@@ -945,6 +950,11 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter,
size_t tot_len; size_t tot_len;
ssize_t ret = 0; ssize_t ret = 0;
if (!(file->f_mode & FMODE_WRITE))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_WRITE))
return -EINVAL;
tot_len = iov_iter_count(iter); tot_len = iov_iter_count(iter);
if (!tot_len) if (!tot_len)
return 0; return 0;
...@@ -971,17 +981,12 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, ...@@ -971,17 +981,12 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
struct iov_iter iter; struct iov_iter iter;
ssize_t ret; ssize_t ret;
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
return -EINVAL;
ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter);
if (ret < 0) if (ret >= 0) {
return ret; ret = do_iter_read(file, &iter, pos, flags);
kfree(iov);
}
ret = do_iter_read(file, &iter, pos, flags);
kfree(iov);
return ret; return ret;
} }
EXPORT_SYMBOL(vfs_readv); EXPORT_SYMBOL(vfs_readv);
...@@ -994,17 +999,11 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, ...@@ -994,17 +999,11 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
struct iov_iter iter; struct iov_iter iter;
ssize_t ret; ssize_t ret;
if (!(file->f_mode & FMODE_WRITE))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_WRITE))
return -EINVAL;
ret = import_iovec(WRITE, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); ret = import_iovec(WRITE, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter);
if (ret < 0) if (ret >= 0) {
return ret; ret = do_iter_write(file, &iter, pos, flags);
kfree(iov);
ret = do_iter_write(file, &iter, pos, flags); }
kfree(iov);
return ret; return ret;
} }
EXPORT_SYMBOL(vfs_writev); EXPORT_SYMBOL(vfs_writev);
...@@ -1161,21 +1160,13 @@ static size_t compat_readv(struct file *file, ...@@ -1161,21 +1160,13 @@ static size_t compat_readv(struct file *file,
struct iovec iovstack[UIO_FASTIOV]; struct iovec iovstack[UIO_FASTIOV];
struct iovec *iov = iovstack; struct iovec *iov = iovstack;
struct iov_iter iter; struct iov_iter iter;
ssize_t ret = -EBADF; ssize_t ret;
if (!(file->f_mode & FMODE_READ))
goto out;
ret = -EINVAL;
if (!(file->f_mode & FMODE_CAN_READ))
goto out;
ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter); ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter);
if (ret < 0) if (ret >= 0) {
goto out; ret = do_iter_read(file, &iter, pos, flags);
ret = do_iter_read(file, &iter, pos, flags); kfree(iov);
kfree(iov); }
out:
if (ret > 0) if (ret > 0)
add_rchar(current, ret); add_rchar(current, ret);
inc_syscr(current); inc_syscr(current);
...@@ -1274,21 +1265,13 @@ static size_t compat_writev(struct file *file, ...@@ -1274,21 +1265,13 @@ static size_t compat_writev(struct file *file,
struct iovec iovstack[UIO_FASTIOV]; struct iovec iovstack[UIO_FASTIOV];
struct iovec *iov = iovstack; struct iovec *iov = iovstack;
struct iov_iter iter; struct iov_iter iter;
ssize_t ret = -EBADF; ssize_t ret;
if (!(file->f_mode & FMODE_WRITE))
goto out;
ret = -EINVAL;
if (!(file->f_mode & FMODE_CAN_WRITE))
goto out;
ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter); ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter);
if (ret < 0) if (ret >= 0) {
goto out; ret = do_iter_write(file, &iter, pos, flags);
ret = do_iter_write(file, &iter, pos, flags); kfree(iov);
kfree(iov); }
out:
if (ret > 0) if (ret > 0)
add_wchar(current, ret); add_wchar(current, ret);
inc_syscw(current); inc_syscw(current);
......
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