Skip to content

Commit 94cd832

Browse files
isilenceaxboe
authored andcommitted
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>
1 parent e279bb4 commit 94cd832

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

io_uring/io_uring.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,13 +2765,6 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
27652765

27662766
*sq_offset = SIZE_MAX;
27672767

2768-
off = struct_size(rings, cqes, cq_entries);
2769-
if (off == SIZE_MAX)
2770-
return SIZE_MAX;
2771-
if (flags & IORING_SETUP_CQE32) {
2772-
if (check_shl_overflow(off, 1, &off))
2773-
return SIZE_MAX;
2774-
}
27752768
if (flags & IORING_SETUP_CQE_MIXED) {
27762769
if (cq_entries < 2)
27772770
return SIZE_MAX;
@@ -2781,6 +2774,12 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
27812774
return SIZE_MAX;
27822775
}
27832776

2777+
off = struct_size(rings, cqes, cq_entries);
2778+
if (flags & IORING_SETUP_CQE32)
2779+
off = size_mul(off, 2);
2780+
if (off == SIZE_MAX)
2781+
return SIZE_MAX;
2782+
27842783
#ifdef CONFIG_SMP
27852784
off = ALIGN(off, SMP_CACHE_BYTES);
27862785
if (off == 0)
@@ -2793,9 +2792,8 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
27932792
*sq_offset = off;
27942793

27952794
sq_array_size = array_size(sizeof(u32), sq_entries);
2796-
if (sq_array_size == SIZE_MAX)
2797-
return SIZE_MAX;
2798-
if (check_add_overflow(off, sq_array_size, &off))
2795+
off = size_add(off, sq_array_size);
2796+
if (off == SIZE_MAX)
27992797
return SIZE_MAX;
28002798
}
28012799

0 commit comments

Comments
 (0)