bpf: task_group_seq_get_next: cleanup the usage of get/put_task_struct
authorOleg Nesterov <oleg@redhat.com>
Tue, 5 Sep 2023 15:46:49 +0000 (17:46 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 8 Sep 2023 15:42:19 +0000 (08:42 -0700)
commit4981921350452a7639fac9ac8f19be4d25febdca
tree50019e301467b3abe0c35e9786db320fc545ce36
parent1a00ef57d9f120b711b6b1193d12ba3789d47ec2
bpf: task_group_seq_get_next: cleanup the usage of get/put_task_struct

get_pid_task() makes no sense, the code does put_task_struct() soon after.
Use find_task_by_pid_ns() instead of find_pid_ns + get_pid_task and kill
put_task_struct(), this allows to do get_task_struct() only once before
return.

While at it, kill the unnecessary "if (!pid)" check in the "if (!*tid)"
block, this matches the next usage of find_pid_ns() + get_pid_task() in
this function.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20230905154649.GA24935@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/task_iter.c