From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH 2/7] io_uring: use size_add helpers for ring offsets
Date: Wed, 12 Nov 2025 12:45:54 +0000 [thread overview]
Message-ID: <fb0ed7f3a2fea660a69b5d0ff26b3b089e20f7e6.1762947814.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1762947814.git.asml.silence@gmail.com>
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>
---
io_uring/io_uring.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index b37beb1cfefe..57ebba8ba46c 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;
}
--
2.49.0
next prev parent reply other threads:[~2025-11-12 12:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 12:45 [PATCH 0/7] further ring init cleanups Pavel Begunkov
2025-11-12 12:45 ` [PATCH 1/7] io_uring: refactor rings_size nosqarray handling Pavel Begunkov
2025-11-12 12:45 ` Pavel Begunkov [this message]
2025-11-12 12:45 ` [PATCH 3/7] io_uring: convert params to pointer in ring reisze Pavel Begunkov
2025-11-12 12:45 ` [PATCH 4/7] io_uring: introduce struct io_ctx_config Pavel Begunkov
2025-11-12 12:45 ` [PATCH 5/7] io_uring: keep ring laoyut in a structure Pavel Begunkov
2025-11-12 12:45 ` [PATCH 6/7] io_uring: pre-calculate scq layout Pavel Begunkov
2025-11-12 12:45 ` [PATCH 7/7] io_uring: move cq/sq user offset init around Pavel Begunkov
2025-11-12 19:33 ` [PATCH 0/7] further ring init cleanups Jens Axboe
2025-11-13 14:28 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fb0ed7f3a2fea660a69b5d0ff26b3b089e20f7e6.1762947814.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox