Skip to content

Commit ac8148d

Browse files
oleg-nesterovAlexei Starovoitov
authored andcommitted
bpf: bpf_iter_task_next: use next_task(kit->task) rather than next_task(kit->pos)
This looks more clear and simplifies the code. While at it, remove the unnecessary initialization of pos/task at the start of bpf_iter_task_new(). Note that we can even kill kit->task, we can just use pos->group_leader, but I don't understand the BUILD_BUG_ON() checks in bpf_iter_task_new(). Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 5a34f9d commit ac8148d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

kernel/bpf/task_iter.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,6 @@ __bpf_kfunc int bpf_iter_task_new(struct bpf_iter_task *it,
978978
BUILD_BUG_ON(__alignof__(struct bpf_iter_task_kern) !=
979979
__alignof__(struct bpf_iter_task));
980980

981-
kit->task = kit->pos = NULL;
982981
switch (flags) {
983982
case BPF_TASK_ITER_ALL_THREADS:
984983
case BPF_TASK_ITER_ALL_PROCS:
@@ -1016,18 +1015,15 @@ __bpf_kfunc struct task_struct *bpf_iter_task_next(struct bpf_iter_task *it)
10161015
goto get_next_task;
10171016

10181017
kit->pos = __next_thread(kit->pos);
1019-
if (!kit->pos) {
1020-
if (flags == BPF_TASK_ITER_PROC_THREADS)
1021-
return pos;
1022-
kit->pos = kit->task;
1023-
} else
1018+
if (kit->pos || flags == BPF_TASK_ITER_PROC_THREADS)
10241019
return pos;
10251020

10261021
get_next_task:
1027-
kit->pos = next_task(kit->pos);
1028-
kit->task = kit->pos;
1029-
if (kit->pos == &init_task)
1022+
kit->task = next_task(kit->task);
1023+
if (kit->task == &init_task)
10301024
kit->pos = NULL;
1025+
else
1026+
kit->pos = kit->task;
10311027

10321028
return pos;
10331029
}

0 commit comments

Comments
 (0)