Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/timeout: add helper for parsing user time

There is some duplication for timespec checks that can be deduplicated
with a new function, and it'll be extended in next patches.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
6e3f5943 484ae637

+20 -9
+20 -9
io_uring/timeout.c
··· 35 35 bool ltimeout; 36 36 }; 37 37 38 + static int io_parse_user_time(struct timespec64 *ts_out, u64 arg) 39 + { 40 + struct timespec64 ts; 41 + 42 + if (get_timespec64(&ts, u64_to_user_ptr(arg))) 43 + return -EFAULT; 44 + if (ts.tv_sec < 0 || ts.tv_nsec < 0) 45 + return -EINVAL; 46 + *ts_out = ts; 47 + return 0; 48 + } 49 + 38 50 static struct io_kiocb *__io_disarm_linked_timeout(struct io_kiocb *req, 39 51 struct io_kiocb *link); 40 52 ··· 458 446 int io_timeout_remove_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 459 447 { 460 448 struct io_timeout_rem *tr = io_kiocb_to_cmd(req, struct io_timeout_rem); 449 + int ret; 461 450 462 451 if (unlikely(req->flags & (REQ_F_FIXED_FILE | REQ_F_BUFFER_SELECT))) 463 452 return -EINVAL; ··· 477 464 tr->ltimeout = true; 478 465 if (tr->flags & ~(IORING_TIMEOUT_UPDATE_MASK|IORING_TIMEOUT_ABS)) 479 466 return -EINVAL; 480 - if (get_timespec64(&tr->ts, u64_to_user_ptr(READ_ONCE(sqe->addr2)))) 481 - return -EFAULT; 482 - if (tr->ts.tv_sec < 0 || tr->ts.tv_nsec < 0) 483 - return -EINVAL; 467 + ret = io_parse_user_time(&tr->ts, READ_ONCE(sqe->addr2)); 468 + if (ret) 469 + return ret; 484 470 } else if (tr->flags) { 485 471 /* timeout removal doesn't support flags */ 486 472 return -EINVAL; ··· 534 522 struct io_timeout_data *data; 535 523 unsigned flags; 536 524 u32 off = READ_ONCE(sqe->off); 525 + int ret; 537 526 538 527 if (sqe->addr3 || sqe->__pad2[0]) 539 528 return -EINVAL; ··· 574 561 data->req = req; 575 562 data->flags = flags; 576 563 577 - if (get_timespec64(&data->ts, u64_to_user_ptr(READ_ONCE(sqe->addr)))) 578 - return -EFAULT; 579 - 580 - if (data->ts.tv_sec < 0 || data->ts.tv_nsec < 0) 581 - return -EINVAL; 564 + ret = io_parse_user_time(&data->ts, READ_ONCE(sqe->addr)); 565 + if (ret) 566 + return ret; 582 567 583 568 data->mode = io_translate_timeout_mode(flags); 584 569