Skip to contentSkip to conversation

cgroup: remove duplicate code in allocate_cg_link()

PATCH In review Li Zefan 3 participants 3 messages Jul 28, 2008 – Jul 30, 2008 1 message not in the archive

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 cgroup: remove duplicate code in allocate_cg_link()

- just call free_cg_links() in allocate_cg_links()
- the list will get initialized in allocate_cg_links(), so don't init it twice

---
 kernel/cgroup.c |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)
kernel/cgroup.c +12 -18
index 28debe4..249a517 100644
@@ -355,6 +355,17 @@ static struct css_set *find_existing_css_set(
 	return NULL;
 }
 
+static void free_cg_links(struct list_head *tmp)
+{
+	struct cg_cgroup_link *link;
+	struct cg_cgroup_link *saved_link;
+
+	list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
+		list_del(&link->cgrp_link_list);
+		kfree(link);
+	}
+}
+
 /*
  * allocate_cg_links() allocates "count" cg_cgroup_link structures
  * and chains them on tmp through their cgrp_link_list fields. Returns 0 on
@@ -363,17 +374,12 @@ static struct css_set *find_existing_css_set(
 static int allocate_cg_links(int count, struct list_head *tmp)
 {
 	struct cg_cgroup_link *link;
-	struct cg_cgroup_link *saved_link;
 	int i;
 	INIT_LIST_HEAD(tmp);
 	for (i = 0; i < count; i++) {
 		link = kmalloc(sizeof(*link), GFP_KERNEL);
 		if (!link) {
-			list_for_each_entry_safe(link, saved_link, tmp,
-						 cgrp_link_list) {
-				list_del(&link->cgrp_link_list);
-				kfree(link);
-			}
+			free_cg_links(tmp);
 			return -ENOMEM;
 		}
 		list_add(&link->cgrp_link_list, tmp);
@@ -381,17 +387,6 @@ static int allocate_cg_links(int count, struct list_head *tmp)
 	return 0;
 }
 
-static void free_cg_links(struct list_head *tmp)
-{
-	struct cg_cgroup_link *link;
-	struct cg_cgroup_link *saved_link;
-
-	list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
-		list_del(&link->cgrp_link_list);
-		kfree(link);
-	}
-}
-
 /*
  * find_css_set() takes an existing cgroup group and a
  * cgroup object, and returns a css_set object that's
@@ -956,7 +951,6 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
 	struct super_block *sb;
 	struct cgroupfs_root *root;
 	struct list_head tmp_cg_links;
-	INIT_LIST_HEAD(&tmp_cg_links);
 
 	/* First find the desired set of subsystems */
 	ret = parse_cgroupfs_options(data, &opts);
Signature · 1 line
1.5.4.rc3

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 5 lines · Li Zefan

- just call free_cg_links() in allocate_cg_links()
- the list will get initialized in allocate_cg_links(), so don't init it twice

(Belatedly) Acked-by: Paul Menage <[email protected]>

Thanks, looks like a good cleanup.

Quoted 75 lines
---
 kernel/cgroup.c |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)
kernel/cgroup.c +12 -19
index 28debe4..249a517 100644
@@ -355,6 +355,17 @@ static struct css_set *find_existing_css_set(
       return NULL;
 }
 
+static void free_cg_links(struct list_head *tmp)
+{
+       struct cg_cgroup_link *link;
+       struct cg_cgroup_link *saved_link;
+
+       list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
+               list_del(&link->cgrp_link_list);
+               kfree(link);
+       }
+}
+
 /*
 * allocate_cg_links() allocates "count" cg_cgroup_link structures
 * and chains them on tmp through their cgrp_link_list fields. Returns 0 on
@@ -363,17 +374,12 @@ static struct css_set *find_existing_css_set(
 static int allocate_cg_links(int count, struct list_head *tmp)
 {
       struct cg_cgroup_link *link;
-       struct cg_cgroup_link *saved_link;
       int i;
       INIT_LIST_HEAD(tmp);
       for (i = 0; i < count; i++) {
               link = kmalloc(sizeof(*link), GFP_KERNEL);
               if (!link) {
-                       list_for_each_entry_safe(link, saved_link, tmp,
-                                                cgrp_link_list) {
-                               list_del(&link->cgrp_link_list);
-                               kfree(link);
-                       }
+                       free_cg_links(tmp);
                       return -ENOMEM;
               }
               list_add(&link->cgrp_link_list, tmp);
@@ -381,17 +387,6 @@ static int allocate_cg_links(int count, struct list_head *tmp)
       return 0;
 }
 
-static void free_cg_links(struct list_head *tmp)
-{
-       struct cg_cgroup_link *link;
-       struct cg_cgroup_link *saved_link;
-
-       list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
-               list_del(&link->cgrp_link_list);
-               kfree(link);
-       }
-}
-
 /*
 * find_css_set() takes an existing cgroup group and a
 * cgroup object, and returns a css_set object that's
@@ -956,7 +951,6 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
       struct super_block *sb;
       struct cgroupfs_root *root;
       struct list_head tmp_cg_links;
-       INIT_LIST_HEAD(&tmp_cg_links);
 
       /* First find the desired set of subsystems */
       ret = parse_cgroupfs_options(data, &opts);
--

1.5.4.rc3

#3 lore raw
In reply to Li Zefan
Quoted 5 lines · Li Zefan

- just call free_cg_links() in allocate_cg_links()
- the list will get initialized in allocate_cg_links(), so don't init it twice

(Belatedly) Acked-by: Paul Menage <[email protected]>

Thanks, looks like a good cleanup.

Quoted 75 lines
---
 kernel/cgroup.c |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)
kernel/cgroup.c +12 -19
index 28debe4..249a517 100644
@@ -355,6 +355,17 @@ static struct css_set *find_existing_css_set(
       return NULL;
 }
 
+static void free_cg_links(struct list_head *tmp)
+{
+       struct cg_cgroup_link *link;
+       struct cg_cgroup_link *saved_link;
+
+       list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
+               list_del(&link->cgrp_link_list);
+               kfree(link);
+       }
+}
+
 /*
 * allocate_cg_links() allocates "count" cg_cgroup_link structures
 * and chains them on tmp through their cgrp_link_list fields. Returns 0 on
@@ -363,17 +374,12 @@ static struct css_set *find_existing_css_set(
 static int allocate_cg_links(int count, struct list_head *tmp)
 {
       struct cg_cgroup_link *link;
-       struct cg_cgroup_link *saved_link;
       int i;
       INIT_LIST_HEAD(tmp);
       for (i = 0; i < count; i++) {
               link = kmalloc(sizeof(*link), GFP_KERNEL);
               if (!link) {
-                       list_for_each_entry_safe(link, saved_link, tmp,
-                                                cgrp_link_list) {
-                               list_del(&link->cgrp_link_list);
-                               kfree(link);
-                       }
+                       free_cg_links(tmp);
                       return -ENOMEM;
               }
               list_add(&link->cgrp_link_list, tmp);
@@ -381,17 +387,6 @@ static int allocate_cg_links(int count, struct list_head *tmp)
       return 0;
 }
 
-static void free_cg_links(struct list_head *tmp)
-{
-       struct cg_cgroup_link *link;
-       struct cg_cgroup_link *saved_link;
-
-       list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) {
-               list_del(&link->cgrp_link_list);
-               kfree(link);
-       }
-}
-
 /*
 * find_css_set() takes an existing cgroup group and a
 * cgroup object, and returns a css_set object that's
@@ -956,7 +951,6 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
       struct super_block *sb;
       struct cgroupfs_root *root;
       struct list_head tmp_cg_links;
-       INIT_LIST_HEAD(&tmp_cg_links);
 
       /* First find the desired set of subsystems */
       ret = parse_cgroupfs_options(data, &opts);
--

1.5.4.rc3