diff options
author | Tejun Heo <tj@kernel.org> | 2013-02-27 20:04:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:19 -0500 |
commit | d228d9ec2c9a119ce15c6446ebeec05786ab3287 (patch) | |
tree | 42ea38da991b681326ce20736dbae945e796c43d /kernel | |
parent | 54924ea33f3ba702243ba4ab068d7d2852db8098 (diff) |
cgroup: convert to idr_alloc()
Convert to the much saner new idr interface.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.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 | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 888fba457bb3..40e0df6c2a2f 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -5320,7 +5320,7 @@ EXPORT_SYMBOL_GPL(free_css_id); | |||
5320 | static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) | 5320 | static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) |
5321 | { | 5321 | { |
5322 | struct css_id *newid; | 5322 | struct css_id *newid; |
5323 | int myid, error, size; | 5323 | int ret, size; |
5324 | 5324 | ||
5325 | BUG_ON(!ss->use_id); | 5325 | BUG_ON(!ss->use_id); |
5326 | 5326 | ||
@@ -5328,35 +5328,24 @@ static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) | |||
5328 | newid = kzalloc(size, GFP_KERNEL); | 5328 | newid = kzalloc(size, GFP_KERNEL); |
5329 | if (!newid) | 5329 | if (!newid) |
5330 | return ERR_PTR(-ENOMEM); | 5330 | return ERR_PTR(-ENOMEM); |
5331 | /* get id */ | 5331 | |
5332 | if (unlikely(!idr_pre_get(&ss->idr, GFP_KERNEL))) { | 5332 | idr_preload(GFP_KERNEL); |
5333 | error = -ENOMEM; | ||
5334 | goto err_out; | ||
5335 | } | ||
5336 | spin_lock(&ss->id_lock); | 5333 | spin_lock(&ss->id_lock); |
5337 | /* Don't use 0. allocates an ID of 1-65535 */ | 5334 | /* Don't use 0. allocates an ID of 1-65535 */ |
5338 | error = idr_get_new_above(&ss->idr, newid, 1, &myid); | 5335 | ret = idr_alloc(&ss->idr, newid, 1, CSS_ID_MAX + 1, GFP_NOWAIT); |
5339 | spin_unlock(&ss->id_lock); | 5336 | spin_unlock(&ss->id_lock); |
5337 | idr_preload_end(); | ||
5340 | 5338 | ||
5341 | /* Returns error when there are no free spaces for new ID.*/ | 5339 | /* Returns error when there are no free spaces for new ID.*/ |
5342 | if (error) { | 5340 | if (ret < 0) |
5343 | error = -ENOSPC; | ||
5344 | goto err_out; | 5341 | goto err_out; |
5345 | } | ||
5346 | if (myid > CSS_ID_MAX) | ||
5347 | goto remove_idr; | ||
5348 | 5342 | ||
5349 | newid->id = myid; | 5343 | newid->id = ret; |
5350 | newid->depth = depth; | 5344 | newid->depth = depth; |
5351 | return newid; | 5345 | return newid; |
5352 | remove_idr: | ||
5353 | error = -ENOSPC; | ||
5354 | spin_lock(&ss->id_lock); | ||
5355 | idr_remove(&ss->idr, myid); | ||
5356 | spin_unlock(&ss->id_lock); | ||
5357 | err_out: | 5346 | err_out: |
5358 | kfree(newid); | 5347 | kfree(newid); |
5359 | return ERR_PTR(error); | 5348 | return ERR_PTR(ret); |
5360 | 5349 | ||
5361 | } | 5350 | } |
5362 | 5351 | ||