Commit 9cc8cbc7 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Linus Torvalds
Browse files

[PATCH] simply fix first_tgid

Like the bug Oleg spotted in first_tid there was also a small off by one
error in first_tgid, when a seek was done on the /proc directory.  This
fixes that and changes the code structure to make it a little more obvious
what is going on.
Signed-off-by: default avatarEric W. Biederman <>
Cc: Oleg Nesterov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent de758734
......@@ -2040,34 +2040,32 @@ static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry
* In the case of a seek we start with &init_task and walk nr
* threads past it.
static struct task_struct *first_tgid(int tgid, int nr)
static struct task_struct *first_tgid(int tgid, unsigned int nr)
struct task_struct *pos = NULL;
struct task_struct *pos;
if (tgid && nr) {
pos = find_task_by_pid(tgid);
if (pos && !thread_group_leader(pos))
pos = NULL;
if (pos)
nr = 0;
if (pos && thread_group_leader(pos))
goto found;
/* If nr exceeds the number of processes get out quickly */
pos = NULL;
if (nr && nr >= nr_processes())
goto done;
/* If we haven't found our starting place yet start with
* the init_task and walk nr tasks forward.
if (!pos && (nr >= 0))
pos = next_task(&init_task);
for (; pos && pid_alive(pos); pos = next_task(pos)) {
if (--nr > 0)
goto done;
for (pos = next_task(&init_task); nr > 0; --nr) {
pos = next_task(pos);
if (pos == &init_task) {
pos = NULL;
goto done;
pos = NULL;
return pos;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment