Skip to content

Commit e944624

Browse files
axboeopsiff
authored andcommitted
exit: move core of do_wait() into helper
Rather than have a maze of gotos, put the actual logic in __do_wait() and have do_wait() loop deal with waitqueue setup/teardown and whether to call __do_wait() again. No functional changes intended in this patch. Acked-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit 06a101c) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 50405ed commit e944624

1 file changed

Lines changed: 31 additions & 20 deletions

File tree

kernel/exit.c

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,16 +1599,10 @@ static int do_wait_pid(struct wait_opts *wo)
15991599
return 0;
16001600
}
16011601

1602-
static long do_wait(struct wait_opts *wo)
1602+
static long __do_wait(struct wait_opts *wo)
16031603
{
1604-
int retval;
1605-
1606-
trace_sched_process_wait(wo->wo_pid);
1604+
long retval;
16071605

1608-
init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
1609-
wo->child_wait.private = current;
1610-
add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1611-
repeat:
16121606
/*
16131607
* If there is nothing that can match our criteria, just get out.
16141608
* We will clear ->notask_error to zero if we see any child that
@@ -1620,24 +1614,23 @@ static long do_wait(struct wait_opts *wo)
16201614
(!wo->wo_pid || !pid_has_task(wo->wo_pid, wo->wo_type)))
16211615
goto notask;
16221616

1623-
set_current_state(TASK_INTERRUPTIBLE);
16241617
read_lock(&tasklist_lock);
16251618

16261619
if (wo->wo_type == PIDTYPE_PID) {
16271620
retval = do_wait_pid(wo);
16281621
if (retval)
1629-
goto end;
1622+
return retval;
16301623
} else {
16311624
struct task_struct *tsk = current;
16321625

16331626
do {
16341627
retval = do_wait_thread(wo, tsk);
16351628
if (retval)
1636-
goto end;
1629+
return retval;
16371630

16381631
retval = ptrace_do_wait(wo, tsk);
16391632
if (retval)
1640-
goto end;
1633+
return retval;
16411634

16421635
if (wo->wo_flags & __WNOTHREAD)
16431636
break;
@@ -1647,14 +1640,32 @@ static long do_wait(struct wait_opts *wo)
16471640

16481641
notask:
16491642
retval = wo->notask_error;
1650-
if (!retval && !(wo->wo_flags & WNOHANG)) {
1651-
retval = -ERESTARTSYS;
1652-
if (!signal_pending(current)) {
1653-
schedule();
1654-
goto repeat;
1655-
}
1656-
}
1657-
end:
1643+
if (!retval && !(wo->wo_flags & WNOHANG))
1644+
return -ERESTARTSYS;
1645+
1646+
return retval;
1647+
}
1648+
1649+
static long do_wait(struct wait_opts *wo)
1650+
{
1651+
int retval;
1652+
1653+
trace_sched_process_wait(wo->wo_pid);
1654+
1655+
init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
1656+
wo->child_wait.private = current;
1657+
add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1658+
1659+
do {
1660+
set_current_state(TASK_INTERRUPTIBLE);
1661+
retval = __do_wait(wo);
1662+
if (retval != -ERESTARTSYS)
1663+
break;
1664+
if (signal_pending(current))
1665+
break;
1666+
schedule();
1667+
} while (1);
1668+
16581669
__set_current_state(TASK_RUNNING);
16591670
remove_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
16601671
return retval;

0 commit comments

Comments
 (0)