Commit d228d9ec authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

cgroup: convert to idr_alloc()

Convert to the much saner new idr interface.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 54924ea3
...@@ -5320,7 +5320,7 @@ EXPORT_SYMBOL_GPL(free_css_id); ...@@ -5320,7 +5320,7 @@ EXPORT_SYMBOL_GPL(free_css_id);
static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth)
{ {
struct css_id *newid; struct css_id *newid;
int myid, error, size; int ret, size;
BUG_ON(!ss->use_id); BUG_ON(!ss->use_id);
...@@ -5328,35 +5328,24 @@ static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) ...@@ -5328,35 +5328,24 @@ static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth)
newid = kzalloc(size, GFP_KERNEL); newid = kzalloc(size, GFP_KERNEL);
if (!newid) if (!newid)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/* get id */
if (unlikely(!idr_pre_get(&ss->idr, GFP_KERNEL))) { idr_preload(GFP_KERNEL);
error = -ENOMEM;
goto err_out;
}
spin_lock(&ss->id_lock); spin_lock(&ss->id_lock);
/* Don't use 0. allocates an ID of 1-65535 */ /* Don't use 0. allocates an ID of 1-65535 */
error = idr_get_new_above(&ss->idr, newid, 1, &myid); ret = idr_alloc(&ss->idr, newid, 1, CSS_ID_MAX + 1, GFP_NOWAIT);
spin_unlock(&ss->id_lock); spin_unlock(&ss->id_lock);
idr_preload_end();
/* Returns error when there are no free spaces for new ID.*/ /* Returns error when there are no free spaces for new ID.*/
if (error) { if (ret < 0)
error = -ENOSPC;
goto err_out; goto err_out;
}
if (myid > CSS_ID_MAX)
goto remove_idr;
newid->id = myid; newid->id = ret;
newid->depth = depth; newid->depth = depth;
return newid; return newid;
remove_idr:
error = -ENOSPC;
spin_lock(&ss->id_lock);
idr_remove(&ss->idr, myid);
spin_unlock(&ss->id_lock);
err_out: err_out:
kfree(newid); kfree(newid);
return ERR_PTR(error); return ERR_PTR(ret);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment