From 626c47124020d6ea15a4f5de517cc11186299cf7 Mon Sep 17 00:00:00 2001
From: Lingfeng Yang <lfy@google.com>
Date: Tue, 15 Nov 2016 12:40:23 -0800
Subject: [PATCH] Cherry-pick fix to break out of loop in cgroup_attach_task()

Manual pick of

[PATCH] cgroup: fix to break the while loop in cgroup_attach_task() correctly

This makes cts content resolver test not freeze the emulator every once
in a while.

Change-Id: I9ef552d5ae24296e7898ce5c93abfaa9d90c241c
Signed-off-by: Lingfeng Yang <lfy@google.com>
(cherry picked from commit bb9caa7da6905cccb27d584eb0ab2c3c2efa9f19)
---
 kernel/cgroup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 8dc7ec1de429..361efa704fcb 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1995,7 +1995,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 
 		/* @tsk either already exited or can't exit until the end */
 		if (tsk->flags & PF_EXITING)
-			continue;
+			goto next;
 
 		/* as per above, nr_threads may decrease, but not increase. */
 		BUG_ON(i >= group_size);
@@ -2003,7 +2003,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 		ent.cgrp = task_cgroup_from_root(tsk, root);
 		/* nothing to do if this task is already in the cgroup */
 		if (ent.cgrp == cgrp)
-			continue;
+			goto next;
 		/*
 		 * saying GFP_ATOMIC has no effect here because we did prealloc
 		 * earlier, but it's good form to communicate our expectations.
@@ -2012,6 +2012,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 		BUG_ON(retval != 0);
 		i++;
 
+next:
 		if (!threadgroup)
 			break;
 	} while_each_thread(leader, tsk);
-- 
GitLab