diff options
| author | Pavel Begunkov <asml.silence@gmail.com> | 2025-11-12 12:45:54 +0000 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-11-13 07:27:34 -0700 |
| commit | 94cd832916521d8d51b25b40691354c24831c655 (patch) | |
| tree | 1d2ba0270291f9a0c0c892ecd76be598f52ea308 | |
| parent | e279bb4b4c4d012808fb21ff41183a2e76c26679 (diff) | |
io_uring: use size_add helpers for ring offsets
Use size_add / size_mul set of functions for rings_size() calculations.
It's more consistent with struct_size(), and errors are preserved across
a series of calculations, so intermediate result checks can be omitted.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | io_uring/io_uring.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index c1dc4bf3cf62..bd8dfa919b61 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2765,13 +2765,6 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries, *sq_offset = SIZE_MAX; - off = struct_size(rings, cqes, cq_entries); - if (off == SIZE_MAX) - return SIZE_MAX; - if (flags & IORING_SETUP_CQE32) { - if (check_shl_overflow(off, 1, &off)) - return SIZE_MAX; - } if (flags & IORING_SETUP_CQE_MIXED) { if (cq_entries < 2) return SIZE_MAX; @@ -2781,6 +2774,12 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries, return SIZE_MAX; } + off = struct_size(rings, cqes, cq_entries); + if (flags & IORING_SETUP_CQE32) + off = size_mul(off, 2); + if (off == SIZE_MAX) + return SIZE_MAX; + #ifdef CONFIG_SMP off = ALIGN(off, SMP_CACHE_BYTES); if (off == 0) @@ -2793,9 +2792,8 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries, *sq_offset = off; sq_array_size = array_size(sizeof(u32), sq_entries); - if (sq_array_size == SIZE_MAX) - return SIZE_MAX; - if (check_add_overflow(off, sq_array_size, &off)) + off = size_add(off, sq_array_size); + if (off == SIZE_MAX) return SIZE_MAX; } |