Skip to content

Commit d55e5f5

Browse files
committed
io_uring: use u64_to_user_ptr() consistently
We use it in some spots, but not consistently. Convert the rest over, makes it easier to read as well. No functional changes in this patch. Signed-off-by: Jens Axboe <[email protected]>
1 parent fd6c2e4 commit d55e5f5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

fs/io_uring.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ static int io_sendmsg_prep(struct io_kiocb *req, struct io_async_ctx *io)
21572157
unsigned flags;
21582158

21592159
flags = READ_ONCE(sqe->msg_flags);
2160-
msg = (struct user_msghdr __user *)(unsigned long) READ_ONCE(sqe->addr);
2160+
msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
21612161
io->msg.iov = io->msg.fast_iov;
21622162
return sendmsg_copy_msghdr(&io->msg.msg, msg, flags, &io->msg.iov);
21632163
#else
@@ -2239,7 +2239,7 @@ static int io_recvmsg_prep(struct io_kiocb *req, struct io_async_ctx *io)
22392239
unsigned flags;
22402240

22412241
flags = READ_ONCE(sqe->msg_flags);
2242-
msg = (struct user_msghdr __user *)(unsigned long) READ_ONCE(sqe->addr);
2242+
msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
22432243
io->msg.iov = io->msg.fast_iov;
22442244
return recvmsg_copy_msghdr(&io->msg.msg, msg, flags, &io->msg.uaddr,
22452245
&io->msg.iov);
@@ -2273,8 +2273,7 @@ static int io_recvmsg(struct io_kiocb *req, struct io_kiocb **nxt,
22732273
else if (force_nonblock)
22742274
flags |= MSG_DONTWAIT;
22752275

2276-
msg = (struct user_msghdr __user *) (unsigned long)
2277-
READ_ONCE(sqe->addr);
2276+
msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
22782277
if (req->io) {
22792278
kmsg = &req->io->msg;
22802279
kmsg->msg.msg_name = &addr;
@@ -2331,9 +2330,8 @@ static int io_accept_prep(struct io_kiocb *req)
23312330
if (sqe->ioprio || sqe->len || sqe->buf_index)
23322331
return -EINVAL;
23332332

2334-
accept->addr = (struct sockaddr __user *)
2335-
(unsigned long) READ_ONCE(sqe->addr);
2336-
accept->addr_len = (int __user *) (unsigned long) READ_ONCE(sqe->addr2);
2333+
accept->addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
2334+
accept->addr_len = u64_to_user_ptr(READ_ONCE(sqe->addr2));
23372335
accept->flags = READ_ONCE(sqe->accept_flags);
23382336
req->flags |= REQ_F_PREPPED;
23392337
return 0;
@@ -2407,7 +2405,7 @@ static int io_connect_prep(struct io_kiocb *req, struct io_async_ctx *io)
24072405
struct sockaddr __user *addr;
24082406
int addr_len;
24092407

2410-
addr = (struct sockaddr __user *) (unsigned long) READ_ONCE(sqe->addr);
2408+
addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
24112409
addr_len = READ_ONCE(sqe->addr2);
24122410
return move_addr_to_kernel(addr, addr_len, &io->connect.address);
24132411
#else
@@ -4702,7 +4700,7 @@ static int io_copy_iov(struct io_ring_ctx *ctx, struct iovec *dst,
47024700
if (copy_from_user(&ciov, &ciovs[index], sizeof(ciov)))
47034701
return -EFAULT;
47044702

4705-
dst->iov_base = (void __user *) (unsigned long) ciov.iov_base;
4703+
dst->iov_base = u64_to_user_ptr((u64)ciov.iov_base);
47064704
dst->iov_len = ciov.iov_len;
47074705
return 0;
47084706
}

0 commit comments

Comments
 (0)