Commit 4c185ce0 authored by Al Viro's avatar Al Viro

aio: lift iov_iter_init() into aio_setup_..._rw()

the only non-trivial detail is that we do it before rw_verify_area(),
so we'd better cap the length ourselves in aio_setup_single_rw()
case (for vectored case rw_copy_check_uvector() will do that for us).
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent ac15ac06
...@@ -1357,7 +1357,8 @@ static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb, ...@@ -1357,7 +1357,8 @@ static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb,
unsigned long *nr_segs, unsigned long *nr_segs,
size_t *len, size_t *len,
struct iovec **iovec, struct iovec **iovec,
bool compat) bool compat,
struct iov_iter *iter)
{ {
ssize_t ret; ssize_t ret;
...@@ -1378,6 +1379,7 @@ static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb, ...@@ -1378,6 +1379,7 @@ static ssize_t aio_setup_vectored_rw(struct kiocb *kiocb,
/* len now reflect bytes instead of segs */ /* len now reflect bytes instead of segs */
*len = ret; *len = ret;
iov_iter_init(iter, rw, *iovec, *nr_segs, *len);
return 0; return 0;
} }
...@@ -1385,14 +1387,18 @@ static ssize_t aio_setup_single_vector(struct kiocb *kiocb, ...@@ -1385,14 +1387,18 @@ static ssize_t aio_setup_single_vector(struct kiocb *kiocb,
int rw, char __user *buf, int rw, char __user *buf,
unsigned long *nr_segs, unsigned long *nr_segs,
size_t len, size_t len,
struct iovec *iovec) struct iovec *iovec,
struct iov_iter *iter)
{ {
if (len > MAX_RW_COUNT)
len = MAX_RW_COUNT;
if (unlikely(!access_ok(!rw, buf, len))) if (unlikely(!access_ok(!rw, buf, len)))
return -EFAULT; return -EFAULT;
iovec->iov_base = buf; iovec->iov_base = buf;
iovec->iov_len = len; iovec->iov_len = len;
*nr_segs = 1; *nr_segs = 1;
iov_iter_init(iter, rw, iovec, *nr_segs, len);
return 0; return 0;
} }
...@@ -1438,10 +1444,10 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode, ...@@ -1438,10 +1444,10 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode,
if (opcode == IOCB_CMD_PREADV || opcode == IOCB_CMD_PWRITEV) if (opcode == IOCB_CMD_PREADV || opcode == IOCB_CMD_PWRITEV)
ret = aio_setup_vectored_rw(req, rw, buf, &nr_segs, ret = aio_setup_vectored_rw(req, rw, buf, &nr_segs,
&len, &iovec, compat); &len, &iovec, compat, &iter);
else else
ret = aio_setup_single_vector(req, rw, buf, &nr_segs, ret = aio_setup_single_vector(req, rw, buf, &nr_segs,
len, iovec); len, iovec, &iter);
if (!ret) if (!ret)
ret = rw_verify_area(rw, file, &req->ki_pos, len); ret = rw_verify_area(rw, file, &req->ki_pos, len);
if (ret < 0) { if (ret < 0) {
...@@ -1463,10 +1469,9 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode, ...@@ -1463,10 +1469,9 @@ static ssize_t aio_run_iocb(struct kiocb *req, unsigned opcode,
file_start_write(file); file_start_write(file);
if (iter_op) { if (iter_op) {
iov_iter_init(&iter, rw, iovec, nr_segs, len);
ret = iter_op(req, &iter); ret = iter_op(req, &iter);
} else { } else {
ret = rw_op(req, iovec, nr_segs, req->ki_pos); ret = rw_op(req, iter.iov, iter.nr_segs, req->ki_pos);
} }
if (rw == WRITE) if (rw == WRITE)
......
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