@@ -916,7 +916,6 @@ static bool io_link_cancel_timeout(struct io_kiocb *req)
916
916
static void io_req_link_next (struct io_kiocb * req , struct io_kiocb * * nxtptr )
917
917
{
918
918
struct io_ring_ctx * ctx = req -> ctx ;
919
- struct io_kiocb * nxt ;
920
919
bool wake_ev = false;
921
920
922
921
/* Already got next link */
@@ -928,24 +927,21 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
928
927
* potentially happen if the chain is messed up, check to be on the
929
928
* safe side.
930
929
*/
931
- nxt = list_first_entry_or_null ( & req -> link_list , struct io_kiocb , list );
932
- while ( nxt ) {
933
- list_del_init ( & nxt -> list );
930
+ while (! list_empty ( & req -> link_list )) {
931
+ struct io_kiocb * nxt = list_first_entry ( & req -> link_list ,
932
+ struct io_kiocb , link_list );
934
933
935
- if ((req -> flags & REQ_F_LINK_TIMEOUT ) &&
936
- (nxt -> flags & REQ_F_TIMEOUT )) {
934
+ if (unlikely ((req -> flags & REQ_F_LINK_TIMEOUT ) &&
935
+ (nxt -> flags & REQ_F_TIMEOUT ))) {
936
+ list_del_init (& nxt -> link_list );
937
937
wake_ev |= io_link_cancel_timeout (nxt );
938
- nxt = list_first_entry_or_null (& req -> link_list ,
939
- struct io_kiocb , list );
940
938
req -> flags &= ~REQ_F_LINK_TIMEOUT ;
941
939
continue ;
942
940
}
943
- if (!list_empty (& req -> link_list )) {
944
- INIT_LIST_HEAD (& nxt -> link_list );
945
- list_splice (& req -> link_list , & nxt -> link_list );
946
- nxt -> flags |= REQ_F_LINK ;
947
- }
948
941
942
+ list_del_init (& req -> link_list );
943
+ if (!list_empty (& nxt -> link_list ))
944
+ nxt -> flags |= REQ_F_LINK ;
949
945
* nxtptr = nxt ;
950
946
break ;
951
947
}
@@ -961,15 +957,15 @@ static void io_req_link_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
961
957
static void io_fail_links (struct io_kiocb * req )
962
958
{
963
959
struct io_ring_ctx * ctx = req -> ctx ;
964
- struct io_kiocb * link ;
965
960
unsigned long flags ;
966
961
967
962
spin_lock_irqsave (& ctx -> completion_lock , flags );
968
963
969
964
while (!list_empty (& req -> link_list )) {
970
- link = list_first_entry (& req -> link_list , struct io_kiocb , list );
971
- list_del_init ( & link -> list );
965
+ struct io_kiocb * link = list_first_entry (& req -> link_list ,
966
+ struct io_kiocb , link_list );
972
967
968
+ list_del_init (& link -> link_list );
973
969
trace_io_uring_fail_link (req , link );
974
970
975
971
if ((req -> flags & REQ_F_LINK_TIMEOUT ) &&
@@ -3170,10 +3166,11 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
3170
3166
* We don't expect the list to be empty, that will only happen if we
3171
3167
* race with the completion of the linked work.
3172
3168
*/
3173
- if (!list_empty (& req -> list )) {
3174
- prev = list_entry (req -> list .prev , struct io_kiocb , link_list );
3169
+ if (!list_empty (& req -> link_list )) {
3170
+ prev = list_entry (req -> link_list .prev , struct io_kiocb ,
3171
+ link_list );
3175
3172
if (refcount_inc_not_zero (& prev -> refs )) {
3176
- list_del_init (& req -> list );
3173
+ list_del_init (& req -> link_list );
3177
3174
prev -> flags &= ~REQ_F_LINK_TIMEOUT ;
3178
3175
} else
3179
3176
prev = NULL ;
@@ -3203,7 +3200,7 @@ static void io_queue_linked_timeout(struct io_kiocb *req)
3203
3200
* we got a chance to setup the timer
3204
3201
*/
3205
3202
spin_lock_irq (& ctx -> completion_lock );
3206
- if (!list_empty (& req -> list )) {
3203
+ if (!list_empty (& req -> link_list )) {
3207
3204
struct io_timeout_data * data = & req -> io -> timeout ;
3208
3205
3209
3206
data -> timer .function = io_link_timeout_fn ;
@@ -3223,7 +3220,8 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
3223
3220
if (!(req -> flags & REQ_F_LINK ))
3224
3221
return NULL ;
3225
3222
3226
- nxt = list_first_entry_or_null (& req -> link_list , struct io_kiocb , list );
3223
+ nxt = list_first_entry_or_null (& req -> link_list , struct io_kiocb ,
3224
+ link_list );
3227
3225
if (!nxt || nxt -> sqe -> opcode != IORING_OP_LINK_TIMEOUT )
3228
3226
return NULL ;
3229
3227
@@ -3364,7 +3362,7 @@ static bool io_submit_sqe(struct io_kiocb *req, struct io_submit_state *state,
3364
3362
goto err_req ;
3365
3363
}
3366
3364
trace_io_uring_link (ctx , req , prev );
3367
- list_add_tail (& req -> list , & prev -> link_list );
3365
+ list_add_tail (& req -> link_list , & prev -> link_list );
3368
3366
} else if (req -> sqe -> flags & IOSQE_IO_LINK ) {
3369
3367
req -> flags |= REQ_F_LINK ;
3370
3368
0 commit comments