Commit 95e49cf8 authored by Jens Axboe's avatar Jens Axboe

iov_iter: add iter_iov_addr() and iter_iov_len() helpers

These just return the address and length of the current iovec segment
in the iterator. Convert existing iov_iter_iovec() users to use them
instead of getting a copy of the current vec.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e4d3202c
...@@ -749,15 +749,14 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, ...@@ -749,15 +749,14 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter,
return -EOPNOTSUPP; return -EOPNOTSUPP;
while (iov_iter_count(iter)) { while (iov_iter_count(iter)) {
struct iovec iovec = iov_iter_iovec(iter);
ssize_t nr; ssize_t nr;
if (type == READ) { if (type == READ) {
nr = filp->f_op->read(filp, iovec.iov_base, nr = filp->f_op->read(filp, iter_iov_addr(iter),
iovec.iov_len, ppos); iter_iov_len(iter), ppos);
} else { } else {
nr = filp->f_op->write(filp, iovec.iov_base, nr = filp->f_op->write(filp, iter_iov_addr(iter),
iovec.iov_len, ppos); iter_iov_len(iter), ppos);
} }
if (nr < 0) { if (nr < 0) {
...@@ -766,7 +765,7 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, ...@@ -766,7 +765,7 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter,
break; break;
} }
ret += nr; ret += nr;
if (nr != iovec.iov_len) if (nr != iter_iov_len(iter))
break; break;
iov_iter_advance(iter, nr); iov_iter_advance(iter, nr);
} }
......
...@@ -70,6 +70,8 @@ struct iov_iter { ...@@ -70,6 +70,8 @@ struct iov_iter {
}; };
#define iter_iov(iter) (iter)->__iov #define iter_iov(iter) (iter)->__iov
#define iter_iov_addr(iter) (iter_iov(iter)->iov_base + (iter)->iov_offset)
#define iter_iov_len(iter) (iter_iov(iter)->iov_len - (iter)->iov_offset)
static inline enum iter_type iov_iter_type(const struct iov_iter *i) static inline enum iter_type iov_iter_type(const struct iov_iter *i)
{ {
......
...@@ -447,26 +447,25 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter) ...@@ -447,26 +447,25 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter)
ppos = io_kiocb_ppos(kiocb); ppos = io_kiocb_ppos(kiocb);
while (iov_iter_count(iter)) { while (iov_iter_count(iter)) {
struct iovec iovec; void __user *addr;
size_t len;
ssize_t nr; ssize_t nr;
if (iter_is_ubuf(iter)) { if (iter_is_ubuf(iter)) {
iovec.iov_base = iter->ubuf + iter->iov_offset; addr = iter->ubuf + iter->iov_offset;
iovec.iov_len = iov_iter_count(iter); len = iov_iter_count(iter);
} else if (!iov_iter_is_bvec(iter)) { } else if (!iov_iter_is_bvec(iter)) {
iovec = iov_iter_iovec(iter); addr = iter_iov_addr(iter);
len = iter_iov_len(iter);
} else { } else {
iovec.iov_base = u64_to_user_ptr(rw->addr); addr = u64_to_user_ptr(rw->addr);
iovec.iov_len = rw->len; len = rw->len;
} }
if (ddir == READ) { if (ddir == READ)
nr = file->f_op->read(file, iovec.iov_base, nr = file->f_op->read(file, addr, len, ppos);
iovec.iov_len, ppos); else
} else { nr = file->f_op->write(file, addr, len, ppos);
nr = file->f_op->write(file, iovec.iov_base,
iovec.iov_len, ppos);
}
if (nr < 0) { if (nr < 0) {
if (!ret) if (!ret)
...@@ -482,7 +481,7 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter) ...@@ -482,7 +481,7 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter)
if (!rw->len) if (!rw->len)
break; break;
} }
if (nr != iovec.iov_len) if (nr != len)
break; break;
} }
......
...@@ -1456,7 +1456,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, ...@@ -1456,7 +1456,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
size_t, vlen, int, behavior, unsigned int, flags) size_t, vlen, int, behavior, unsigned int, flags)
{ {
ssize_t ret; ssize_t ret;
struct iovec iovstack[UIO_FASTIOV], iovec; struct iovec iovstack[UIO_FASTIOV];
struct iovec *iov = iovstack; struct iovec *iov = iovstack;
struct iov_iter iter; struct iov_iter iter;
struct task_struct *task; struct task_struct *task;
...@@ -1503,12 +1503,11 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, ...@@ -1503,12 +1503,11 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
total_len = iov_iter_count(&iter); total_len = iov_iter_count(&iter);
while (iov_iter_count(&iter)) { while (iov_iter_count(&iter)) {
iovec = iov_iter_iovec(&iter); ret = do_madvise(mm, (unsigned long)iter_iov_addr(&iter),
ret = do_madvise(mm, (unsigned long)iovec.iov_base, iter_iov_len(&iter), behavior);
iovec.iov_len, behavior);
if (ret < 0) if (ret < 0)
break; break;
iov_iter_advance(&iter, iovec.iov_len); iov_iter_advance(&iter, iter_iov_len(&iter));
} }
ret = (total_len - iov_iter_count(&iter)) ? : ret; ret = (total_len - iov_iter_count(&iter)) ? : ret;
......
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