Skip to content

Commit e279bb4

Browse files
isilenceaxboe
authored andcommitted
io_uring: refactor rings_size nosqarray handling
A preparation patch inversing the IORING_SETUP_NO_SQARRAY check, this way there is only one successful return path from the function, which will be helpful later. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ecb8490 commit e279bb4

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

io_uring/io_uring.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,9 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
27612761
unsigned int cq_entries, size_t *sq_offset)
27622762
{
27632763
struct io_rings *rings;
2764-
size_t off, sq_array_size;
2764+
size_t off;
2765+
2766+
*sq_offset = SIZE_MAX;
27652767

27662768
off = struct_size(rings, cqes, cq_entries);
27672769
if (off == SIZE_MAX)
@@ -2785,19 +2787,17 @@ unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
27852787
return SIZE_MAX;
27862788
#endif
27872789

2788-
if (flags & IORING_SETUP_NO_SQARRAY) {
2789-
*sq_offset = SIZE_MAX;
2790-
return off;
2791-
}
2792-
2793-
*sq_offset = off;
2790+
if (!(flags & IORING_SETUP_NO_SQARRAY)) {
2791+
size_t sq_array_size;
27942792

2795-
sq_array_size = array_size(sizeof(u32), sq_entries);
2796-
if (sq_array_size == SIZE_MAX)
2797-
return SIZE_MAX;
2793+
*sq_offset = off;
27982794

2799-
if (check_add_overflow(off, sq_array_size, &off))
2800-
return SIZE_MAX;
2795+
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))
2799+
return SIZE_MAX;
2800+
}
28012801

28022802
return off;
28032803
}

0 commit comments

Comments
 (0)