diff options
author | KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> | 2008-07-25 04:46:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:35 -0400 |
commit | 71cbb949d17d4d776abd547135feb7f3282405c8 (patch) | |
tree | decd47a6cb05a36bb8a2f224b50bd12a8acc862e /kernel | |
parent | f2992db2a4f7ae10f61d5bc68c7c1528cec639e2 (diff) |
cgroup: list_for_each cleanup
--------------------------
while() {
list_entry();
...
}
--------------------------
is equivalent to following code.
--------------------------
list_for_each_entry(){
...
}
--------------------------
later can review easily more.
this patch is just clean up.
it doesn't have any behavor change.
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Paul Menage <menage@google.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/cgroup.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index f50edadfdd86..6836a9063634 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -241,17 +241,20 @@ static int use_task_css_set_links; | |||
241 | */ | 241 | */ |
242 | static void unlink_css_set(struct css_set *cg) | 242 | static void unlink_css_set(struct css_set *cg) |
243 | { | 243 | { |
244 | struct cg_cgroup_link *link; | ||
245 | struct cg_cgroup_link *saved_link; | ||
246 | |||
244 | write_lock(&css_set_lock); | 247 | write_lock(&css_set_lock); |
245 | hlist_del(&cg->hlist); | 248 | hlist_del(&cg->hlist); |
246 | css_set_count--; | 249 | css_set_count--; |
247 | while (!list_empty(&cg->cg_links)) { | 250 | |
248 | struct cg_cgroup_link *link; | 251 | list_for_each_entry_safe(link, saved_link, &cg->cg_links, |
249 | link = list_entry(cg->cg_links.next, | 252 | cg_link_list) { |
250 | struct cg_cgroup_link, cg_link_list); | ||
251 | list_del(&link->cg_link_list); | 253 | list_del(&link->cg_link_list); |
252 | list_del(&link->cgrp_link_list); | 254 | list_del(&link->cgrp_link_list); |
253 | kfree(link); | 255 | kfree(link); |
254 | } | 256 | } |
257 | |||
255 | write_unlock(&css_set_lock); | 258 | write_unlock(&css_set_lock); |
256 | } | 259 | } |
257 | 260 | ||
@@ -363,15 +366,14 @@ static struct css_set *find_existing_css_set( | |||
363 | static int allocate_cg_links(int count, struct list_head *tmp) | 366 | static int allocate_cg_links(int count, struct list_head *tmp) |
364 | { | 367 | { |
365 | struct cg_cgroup_link *link; | 368 | struct cg_cgroup_link *link; |
369 | struct cg_cgroup_link *saved_link; | ||
366 | int i; | 370 | int i; |
367 | INIT_LIST_HEAD(tmp); | 371 | INIT_LIST_HEAD(tmp); |
368 | for (i = 0; i < count; i++) { | 372 | for (i = 0; i < count; i++) { |
369 | link = kmalloc(sizeof(*link), GFP_KERNEL); | 373 | link = kmalloc(sizeof(*link), GFP_KERNEL); |
370 | if (!link) { | 374 | if (!link) { |
371 | while (!list_empty(tmp)) { | 375 | list_for_each_entry_safe(link, saved_link, tmp, |
372 | link = list_entry(tmp->next, | 376 | cgrp_link_list) { |
373 | struct cg_cgroup_link, | ||
374 | cgrp_link_list); | ||
375 | list_del(&link->cgrp_link_list); | 377 | list_del(&link->cgrp_link_list); |
376 | kfree(link); | 378 | kfree(link); |
377 | } | 379 | } |
@@ -384,11 +386,10 @@ static int allocate_cg_links(int count, struct list_head *tmp) | |||
384 | 386 | ||
385 | static void free_cg_links(struct list_head *tmp) | 387 | static void free_cg_links(struct list_head *tmp) |
386 | { | 388 | { |
387 | while (!list_empty(tmp)) { | 389 | struct cg_cgroup_link *link; |
388 | struct cg_cgroup_link *link; | 390 | struct cg_cgroup_link *saved_link; |
389 | link = list_entry(tmp->next, | 391 | |
390 | struct cg_cgroup_link, | 392 | list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) { |
391 | cgrp_link_list); | ||
392 | list_del(&link->cgrp_link_list); | 393 | list_del(&link->cgrp_link_list); |
393 | kfree(link); | 394 | kfree(link); |
394 | } | 395 | } |
@@ -1093,6 +1094,8 @@ static void cgroup_kill_sb(struct super_block *sb) { | |||
1093 | struct cgroupfs_root *root = sb->s_fs_info; | 1094 | struct cgroupfs_root *root = sb->s_fs_info; |
1094 | struct cgroup *cgrp = &root->top_cgroup; | 1095 | struct cgroup *cgrp = &root->top_cgroup; |
1095 | int ret; | 1096 | int ret; |
1097 | struct cg_cgroup_link *link; | ||
1098 | struct cg_cgroup_link *saved_link; | ||
1096 | 1099 | ||
1097 | BUG_ON(!root); | 1100 | BUG_ON(!root); |
1098 | 1101 | ||
@@ -1112,10 +1115,9 @@ static void cgroup_kill_sb(struct super_block *sb) { | |||
1112 | * root cgroup | 1115 | * root cgroup |
1113 | */ | 1116 | */ |
1114 | write_lock(&css_set_lock); | 1117 | write_lock(&css_set_lock); |
1115 | while (!list_empty(&cgrp->css_sets)) { | 1118 | |
1116 | struct cg_cgroup_link *link; | 1119 | list_for_each_entry_safe(link, saved_link, &cgrp->css_sets, |
1117 | link = list_entry(cgrp->css_sets.next, | 1120 | cgrp_link_list) { |
1118 | struct cg_cgroup_link, cgrp_link_list); | ||
1119 | list_del(&link->cg_link_list); | 1121 | list_del(&link->cg_link_list); |
1120 | list_del(&link->cgrp_link_list); | 1122 | list_del(&link->cgrp_link_list); |
1121 | kfree(link); | 1123 | kfree(link); |
@@ -1756,15 +1758,11 @@ int cgroup_add_files(struct cgroup *cgrp, | |||
1756 | int cgroup_task_count(const struct cgroup *cgrp) | 1758 | int cgroup_task_count(const struct cgroup *cgrp) |
1757 | { | 1759 | { |
1758 | int count = 0; | 1760 | int count = 0; |
1759 | struct list_head *l; | 1761 | struct cg_cgroup_link *link; |
1760 | 1762 | ||
1761 | read_lock(&css_set_lock); | 1763 | read_lock(&css_set_lock); |
1762 | l = cgrp->css_sets.next; | 1764 | list_for_each_entry(link, &cgrp->css_sets, cgrp_link_list) { |
1763 | while (l != &cgrp->css_sets) { | ||
1764 | struct cg_cgroup_link *link = | ||
1765 | list_entry(l, struct cg_cgroup_link, cgrp_link_list); | ||
1766 | count += atomic_read(&link->cg->ref.refcount); | 1765 | count += atomic_read(&link->cg->ref.refcount); |
1767 | l = l->next; | ||
1768 | } | 1766 | } |
1769 | read_unlock(&css_set_lock); | 1767 | read_unlock(&css_set_lock); |
1770 | return count; | 1768 | return count; |