mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-01 00:58:39 +02:00 
			
		
		
		
	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 <oleg@redhat.com> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20231114163239.GA903@redhat.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
		
							parent
							
								
									5a34f9dabd
								
							
						
					
					
						commit
						ac8148d957
					
				
					 1 changed files with 5 additions and 9 deletions
				
			
		|  | @ -978,7 +978,6 @@ __bpf_kfunc int bpf_iter_task_new(struct bpf_iter_task *it, | ||||||
| 	BUILD_BUG_ON(__alignof__(struct bpf_iter_task_kern) != | 	BUILD_BUG_ON(__alignof__(struct bpf_iter_task_kern) != | ||||||
| 					__alignof__(struct bpf_iter_task)); | 					__alignof__(struct bpf_iter_task)); | ||||||
| 
 | 
 | ||||||
| 	kit->task = kit->pos = NULL; |  | ||||||
| 	switch (flags) { | 	switch (flags) { | ||||||
| 	case BPF_TASK_ITER_ALL_THREADS: | 	case BPF_TASK_ITER_ALL_THREADS: | ||||||
| 	case BPF_TASK_ITER_ALL_PROCS: | 	case BPF_TASK_ITER_ALL_PROCS: | ||||||
|  | @ -1016,18 +1015,15 @@ __bpf_kfunc struct task_struct *bpf_iter_task_next(struct bpf_iter_task *it) | ||||||
| 		goto get_next_task; | 		goto get_next_task; | ||||||
| 
 | 
 | ||||||
| 	kit->pos = __next_thread(kit->pos); | 	kit->pos = __next_thread(kit->pos); | ||||||
| 	if (!kit->pos) { | 	if (kit->pos || flags == BPF_TASK_ITER_PROC_THREADS) | ||||||
| 		if (flags == BPF_TASK_ITER_PROC_THREADS) |  | ||||||
| 			return pos; |  | ||||||
| 		kit->pos = kit->task; |  | ||||||
| 	} else |  | ||||||
| 		return pos; | 		return pos; | ||||||
| 
 | 
 | ||||||
| get_next_task: | get_next_task: | ||||||
| 	kit->pos = next_task(kit->pos); | 	kit->task = next_task(kit->task); | ||||||
| 	kit->task = kit->pos; | 	if (kit->task == &init_task) | ||||||
| 	if (kit->pos == &init_task) |  | ||||||
| 		kit->pos = NULL; | 		kit->pos = NULL; | ||||||
|  | 	else | ||||||
|  | 		kit->pos = kit->task; | ||||||
| 
 | 
 | ||||||
| 	return pos; | 	return pos; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Oleg Nesterov
						Oleg Nesterov