Skip to content

Commit 91b2db2

Browse files
liu-song-6borkmann
authored andcommitted
bpf: Simplify task_file_seq_get_next()
Simplify task_file_seq_get_next() by removing two in/out arguments: task and fstruct. Use info->task and info->files instead. Signed-off-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 450d060 commit 91b2db2

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

kernel/bpf/task_iter.c

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ struct bpf_iter_seq_task_file_info {
136136
};
137137

138138
static struct file *
139-
task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
140-
struct task_struct **task, struct files_struct **fstruct)
139+
task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
141140
{
142141
struct pid_namespace *ns = info->common.ns;
143142
u32 curr_tid = info->tid, max_fds;
@@ -150,14 +149,17 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
150149
* Otherwise, it does not hold any reference.
151150
*/
152151
again:
153-
if (*task) {
154-
curr_task = *task;
155-
curr_files = *fstruct;
152+
if (info->task) {
153+
curr_task = info->task;
154+
curr_files = info->files;
156155
curr_fd = info->fd;
157156
} else {
158157
curr_task = task_seq_get_next(ns, &curr_tid, true);
159-
if (!curr_task)
158+
if (!curr_task) {
159+
info->task = NULL;
160+
info->files = NULL;
160161
return NULL;
162+
}
161163

162164
curr_files = get_files_struct(curr_task);
163165
if (!curr_files) {
@@ -167,9 +169,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
167169
goto again;
168170
}
169171

170-
/* set *fstruct, *task and info->tid */
171-
*fstruct = curr_files;
172-
*task = curr_task;
172+
info->files = curr_files;
173+
info->task = curr_task;
173174
if (curr_tid == info->tid) {
174175
curr_fd = info->fd;
175176
} else {
@@ -199,8 +200,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
199200
rcu_read_unlock();
200201
put_files_struct(curr_files);
201202
put_task_struct(curr_task);
202-
*task = NULL;
203-
*fstruct = NULL;
203+
info->task = NULL;
204+
info->files = NULL;
204205
info->fd = 0;
205206
curr_tid = ++(info->tid);
206207
goto again;
@@ -209,46 +210,25 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info,
209210
static void *task_file_seq_start(struct seq_file *seq, loff_t *pos)
210211
{
211212
struct bpf_iter_seq_task_file_info *info = seq->private;
212-
struct files_struct *files = NULL;
213-
struct task_struct *task = NULL;
214213
struct file *file;
215214

216-
file = task_file_seq_get_next(info, &task, &files);
217-
if (!file) {
218-
info->files = NULL;
219-
info->task = NULL;
220-
return NULL;
221-
}
222-
223-
if (*pos == 0)
215+
info->task = NULL;
216+
info->files = NULL;
217+
file = task_file_seq_get_next(info);
218+
if (file && *pos == 0)
224219
++*pos;
225-
info->task = task;
226-
info->files = files;
227220

228221
return file;
229222
}
230223

231224
static void *task_file_seq_next(struct seq_file *seq, void *v, loff_t *pos)
232225
{
233226
struct bpf_iter_seq_task_file_info *info = seq->private;
234-
struct files_struct *files = info->files;
235-
struct task_struct *task = info->task;
236-
struct file *file;
237227

238228
++*pos;
239229
++info->fd;
240230
fput((struct file *)v);
241-
file = task_file_seq_get_next(info, &task, &files);
242-
if (!file) {
243-
info->files = NULL;
244-
info->task = NULL;
245-
return NULL;
246-
}
247-
248-
info->task = task;
249-
info->files = files;
250-
251-
return file;
231+
return task_file_seq_get_next(info);
252232
}
253233

254234
struct bpf_iter__task_file {

0 commit comments

Comments
 (0)