return ERR_PTR(-EACCES);
}
-static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
+static ssize_t
+ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
{
struct request *req;
struct ublk_io *io;
size_t buf_off;
size_t ret;
- req = ublk_check_and_get_req(iocb, to, &buf_off, ITER_DEST, &io);
+ req = ublk_check_and_get_req(iocb, iter, &buf_off, dir, &io);
if (IS_ERR(req))
return PTR_ERR(req);
- ret = ublk_copy_user_pages(req, buf_off, to, ITER_DEST);
+ ret = ublk_copy_user_pages(req, buf_off, iter, dir);
ublk_put_req_ref(io, req);
return ret;
}
-static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from)
+static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
- struct request *req;
- struct ublk_io *io;
- size_t buf_off;
- size_t ret;
-
- req = ublk_check_and_get_req(iocb, from, &buf_off, ITER_SOURCE, &io);
- if (IS_ERR(req))
- return PTR_ERR(req);
-
- ret = ublk_copy_user_pages(req, buf_off, from, ITER_SOURCE);
- ublk_put_req_ref(io, req);
+ return ublk_user_copy(iocb, to, ITER_DEST);
+}
- return ret;
+static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from)
+{
+ return ublk_user_copy(iocb, from, ITER_SOURCE);
}
static const struct file_operations ublk_ch_fops = {