Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/tctx: avoid modifying loop variable in io_ring_add_registered_file

Use a separate 'idx' variable to store the result of array_index_nospec()
instead of modifying the loop variable 'offset' directly. This improves
code clarity by separating the logical index from the sanitized index
used for array access.

No functional change intended.

Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yang Xiuwei and committed by
Jens Axboe
daa0b901 7cb3a683

+5 -5
+5 -5
io_uring/tctx.c
··· 240 240 int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file, 241 241 int start, int end) 242 242 { 243 - int offset; 243 + int offset, idx; 244 244 for (offset = start; offset < end; offset++) { 245 - offset = array_index_nospec(offset, IO_RINGFD_REG_MAX); 246 - if (tctx->registered_rings[offset]) 245 + idx = array_index_nospec(offset, IO_RINGFD_REG_MAX); 246 + if (tctx->registered_rings[idx]) 247 247 continue; 248 248 249 - tctx->registered_rings[offset] = file; 250 - return offset; 249 + tctx->registered_rings[idx] = file; 250 + return idx; 251 251 } 252 252 return -EBUSY; 253 253 }