diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 64950fa5d3211c5f2843e9637b38452a70eef9f7..a40a2c4384b3555ed588f8f3794f37b584975938 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1638,9 +1638,9 @@ static int pid_array_load(pid_t *pidarray, int npids, struct cpuset *cs)
 
 	do_each_thread(g, p) {
 		if (p->cpuset == cs) {
+			pidarray[n++] = p->pid;
 			if (unlikely(n == npids))
 				goto array_full;
-			pidarray[n++] = p->pid;
 		}
 	} while_each_thread(g, p);