summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-13 12:19:22 -0400
committerTejun Heo <tj@kernel.org>2014-05-13 12:19:22 -0400
commitba0f4d761503bd9ce4c7458b56bfd7c3fdb51e86 (patch)
treec040ae2a79cbf8fcb36898f2f3b5926032df1738 /kernel/cgroup.c
parentb7fc5ad235936379fae67a9f7b50bb53487a1a3a (diff)
downloadtalos-obmc-linux-ba0f4d761503bd9ce4c7458b56bfd7c3fdb51e86.tar.gz
talos-obmc-linux-ba0f4d761503bd9ce4c7458b56bfd7c3fdb51e86.zip
cgroup: reorganize cgroup_create()
Reorganize cgroup_create() so that all paths share unlock out path. * All err_* labels are renamed to out_* as they're now shared by both success and failure paths. * @err renamed to @ret for the similar reason as above and so that it's more consistent with other functions. * cgroup memory allocation moved after locking so that freeing failed cgroup happens before unlocking. While this moves more code inside critical section, memory allocations inside cgroup locking are already pretty common and this is unlikely to make any noticeable difference. * While at it, replace a stray @parent->root dereference with @root. This reorganization will help simplifying locking. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 94d259bcd2b9..1d6106c3fb4e 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4246,15 +4246,10 @@ static long cgroup_create(struct cgroup *parent, const char *name,
{
struct cgroup *cgrp;
struct cgroup_root *root = parent->root;
- int ssid, err;
+ int ssid, ret;
struct cgroup_subsys *ss;
struct kernfs_node *kn;
- /* allocate the cgroup and its ID, 0 is reserved for the root */
- cgrp = kzalloc(sizeof(*cgrp), GFP_KERNEL);
- if (!cgrp)
- return -ENOMEM;
-
mutex_lock(&cgroup_tree_mutex);
/*
@@ -4265,8 +4260,15 @@ static long cgroup_create(struct cgroup *parent, const char *name,
* don't get nasty surprises if we ever grow another caller.
*/
if (!cgroup_lock_live_group(parent)) {
- err = -ENODEV;
- goto err_unlock_tree;
+ ret = -ENODEV;
+ goto out_unlock_tree;
+ }
+
+ /* allocate the cgroup and its ID, 0 is reserved for the root */
+ cgrp = kzalloc(sizeof(*cgrp), GFP_KERNEL);
+ if (!cgrp) {
+ ret = -ENOMEM;
+ goto out_unlock;
}
/*
@@ -4275,15 +4277,15 @@ static long cgroup_create(struct cgroup *parent, const char *name,
*/
cgrp->id = cgroup_idr_alloc(&root->cgroup_idr, NULL, 2, 0, GFP_NOWAIT);
if (cgrp->id < 0) {
- err = -ENOMEM;
- goto err_unlock;
+ ret = -ENOMEM;
+ goto out_free_cgrp;
}
init_cgroup_housekeeping(cgrp);
cgrp->parent = parent;
cgrp->dummy_css.parent = &parent->dummy_css;
- cgrp->root = parent->root;
+ cgrp->root = root;
if (notify_on_release(parent))
set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
@@ -4294,8 +4296,8 @@ static long cgroup_create(struct cgroup *parent, const char *name,
/* create the directory */
kn = kernfs_create_dir(parent->kn, name, mode, cgrp);
if (IS_ERR(kn)) {
- err = PTR_ERR(kn);
- goto err_free_id;
+ ret = PTR_ERR(kn);
+ goto out_free_id;
}
cgrp->kn = kn;
@@ -4318,20 +4320,20 @@ static long cgroup_create(struct cgroup *parent, const char *name,
*/
cgroup_idr_replace(&root->cgroup_idr, cgrp, cgrp->id);
- err = cgroup_kn_set_ugid(kn);
- if (err)
- goto err_destroy;
+ ret = cgroup_kn_set_ugid(kn);
+ if (ret)
+ goto out_destroy;
- err = cgroup_addrm_files(cgrp, cgroup_base_files, true);
- if (err)
- goto err_destroy;
+ ret = cgroup_addrm_files(cgrp, cgroup_base_files, true);
+ if (ret)
+ goto out_destroy;
/* let's create and online css's */
for_each_subsys(ss, ssid) {
if (parent->child_subsys_mask & (1 << ssid)) {
- err = create_css(cgrp, ss);
- if (err)
- goto err_destroy;
+ ret = create_css(cgrp, ss);
+ if (ret)
+ goto out_destroy;
}
}
@@ -4344,25 +4346,22 @@ static long cgroup_create(struct cgroup *parent, const char *name,
kernfs_activate(kn);
- mutex_unlock(&cgroup_mutex);
- mutex_unlock(&cgroup_tree_mutex);
-
- return 0;
+ ret = 0;
+ goto out_unlock;
-err_free_id:
+out_free_id:
cgroup_idr_remove(&root->cgroup_idr, cgrp->id);
-err_unlock:
+out_free_cgrp:
+ kfree(cgrp);
+out_unlock:
mutex_unlock(&cgroup_mutex);
-err_unlock_tree:
+out_unlock_tree:
mutex_unlock(&cgroup_tree_mutex);
- kfree(cgrp);
- return err;
+ return ret;
-err_destroy:
+out_destroy:
cgroup_destroy_locked(cgrp);
- mutex_unlock(&cgroup_mutex);
- mutex_unlock(&cgroup_tree_mutex);
- return err;
+ goto out_unlock;
}
static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
OpenPOWER on IntegriCloud