[PATCH] proc-remove-races-from-proc_id_readdir-factor-out-tgid-increment

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Oleg Nesterov
Date: Tuesday, November 20, 2007 - 9:34 am

On 11/19, Eric W. Biederman wrote:

Nice. Perhaps we can also factor out the incrementing of iter.tgid? Lessens
the generated code, and (imho) cleanups the source a little bit.

(untested, 2.6.24-rc2-mm1 doesn't boot on my machine)

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- PT/fs/proc/base.c~	2007-11-20 19:00:05.000000000 +0300
+++ PT/fs/proc/base.c	2007-11-20 19:06:28.000000000 +0300
@@ -2378,6 +2378,7 @@ static struct tgid_iter next_tgid(struct
 	rcu_read_lock();
 retry:
 	iter.task = NULL;
+	iter.tgid++;
 	pid = find_ge_pid(iter.tgid, ns);
 	if (pid) {
 		iter.tgid = pid_nr_ns(pid, ns);
@@ -2394,10 +2395,8 @@ retry:
 		 * found doesn't happen to be a thread group leader.
 		 * As we don't care in the case of readdir.
 		 */
-		if (!iter.task || !has_group_leader_pid(iter.task)) {
-			iter.tgid += 1;
+		if (!iter.task || !has_group_leader_pid(iter.task))
 			goto retry;
-		}
 		get_task_struct(iter.task);
 	}
 	rcu_read_unlock();
@@ -2434,10 +2433,8 @@ int proc_pid_readdir(struct file * filp,
 
 	ns = filp->f_dentry->d_sb->s_fs_info;
 	iter.task = NULL;
-	iter.tgid = filp->f_pos - TGID_OFFSET;
-	for (iter = next_tgid(ns, iter);
-	     iter.task;
-	     iter.tgid += 1, iter = next_tgid(ns, iter)) {
+	iter.tgid = filp->f_pos - TGID_OFFSET - 1;
+	while ((iter = next_tgid(ns, iter)).task) {
 		filp->f_pos = iter.tgid + TGID_OFFSET;
 		if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
 			put_task_struct(iter.task);

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] task_pid_nr_ns() breaks proc_pid_readdir(), Oleg Nesterov, (Sat Nov 17, 11:15 am)
Re: [PATCH] task_pid_nr_ns() breaks proc_pid_readdir(), Oleg Nesterov, (Sun Nov 18, 7:20 am)
Re: [PATCH] task_pid_nr_ns() breaks proc_pid_readdir(), Oleg Nesterov, (Mon Nov 19, 11:29 am)
Re: [PATCH] task_pid_nr_ns() breaks proc_pid_readdir(), Eric W. Biederman, (Mon Nov 19, 11:50 am)
[PATCH] proc: Remove races from proc_id_readdir(), Eric W. Biederman, (Mon Nov 19, 2:44 pm)
[PATCH] proc-remove-races-from-proc_id_readdir-factor-out- ..., Oleg Nesterov, (Tue Nov 20, 9:34 am)
Re: [PATCH] proc-remove-races-from-proc_id_readdir-factor- ..., Eric W. Biederman, (Tue Nov 20, 1:45 pm)