aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/proc/base.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8180579f8792..bbcaef9adb57 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2040,34 +2040,32 @@ out:
2040 * In the case of a seek we start with &init_task and walk nr 2040 * In the case of a seek we start with &init_task and walk nr
2041 * threads past it. 2041 * threads past it.
2042 */ 2042 */
2043static struct task_struct *first_tgid(int tgid, int nr) 2043static struct task_struct *first_tgid(int tgid, unsigned int nr)
2044{ 2044{
2045 struct task_struct *pos = NULL; 2045 struct task_struct *pos;
2046 rcu_read_lock(); 2046 rcu_read_lock();
2047 if (tgid && nr) { 2047 if (tgid && nr) {
2048 pos = find_task_by_pid(tgid); 2048 pos = find_task_by_pid(tgid);
2049 if (pos && !thread_group_leader(pos)) 2049 if (pos && thread_group_leader(pos))
2050 pos = NULL; 2050 goto found;
2051 if (pos)
2052 nr = 0;
2053 } 2051 }
2054 /* If nr exceeds the number of processes get out quickly */ 2052 /* If nr exceeds the number of processes get out quickly */
2053 pos = NULL;
2055 if (nr && nr >= nr_processes()) 2054 if (nr && nr >= nr_processes())
2056 goto done; 2055 goto done;
2057 2056
2058 /* If we haven't found our starting place yet start with 2057 /* If we haven't found our starting place yet start with
2059 * the init_task and walk nr tasks forward. 2058 * the init_task and walk nr tasks forward.
2060 */ 2059 */
2061 if (!pos && (nr >= 0)) 2060 for (pos = next_task(&init_task); nr > 0; --nr) {
2062 pos = next_task(&init_task); 2061 pos = next_task(pos);
2063 2062 if (pos == &init_task) {
2064 for (; pos && pid_alive(pos); pos = next_task(pos)) { 2063 pos = NULL;
2065 if (--nr > 0) 2064 goto done;
2066 continue; 2065 }
2067 get_task_struct(pos);
2068 goto done;
2069 } 2066 }
2070 pos = NULL; 2067found:
2068 get_task_struct(pos);
2071done: 2069done:
2072 rcu_read_unlock(); 2070 rcu_read_unlock();
2073 return pos; 2071 return pos;