]> Gentwo Git Trees - linux/.git/commitdiff
io_uring: use size_add helpers for ring offsets
authorPavel Begunkov <asml.silence@gmail.com>
Wed, 12 Nov 2025 12:45:54 +0000 (12:45 +0000)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Nov 2025 14:27:34 +0000 (07:27 -0700)
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>
io_uring/io_uring.c

index c1dc4bf3cf62e1dfc75eafe92993638cdd5c99c3..bd8dfa919b6103833521027e249fe6f44249e0be 100644 (file)
@@ -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;
        }