Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Tejun Heo and committed by
Linus Torvalds
d228d9ec 54924ea3

+8 -19
+8 -19
kernel/cgroup.c
··· 5320 5320 static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) 5321 5321 { 5322 5322 struct css_id *newid; 5323 - int myid, error, size; 5323 + int ret, size; 5324 5324 5325 5325 BUG_ON(!ss->use_id); 5326 5326 ··· 5328 5328 newid = kzalloc(size, GFP_KERNEL); 5329 5329 if (!newid) 5330 5330 return ERR_PTR(-ENOMEM); 5331 - /* get id */ 5332 - if (unlikely(!idr_pre_get(&ss->idr, GFP_KERNEL))) { 5333 - error = -ENOMEM; 5334 - goto err_out; 5335 - } 5331 + 5332 + idr_preload(GFP_KERNEL); 5336 5333 spin_lock(&ss->id_lock); 5337 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 5336 spin_unlock(&ss->id_lock); 5337 + idr_preload_end(); 5340 5338 5341 5339 /* Returns error when there are no free spaces for new ID.*/ 5342 - if (error) { 5343 - error = -ENOSPC; 5340 + if (ret < 0) 5344 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 5344 newid->depth = depth; 5351 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 5346 err_out: 5358 5347 kfree(newid); 5359 - return ERR_PTR(error); 5348 + return ERR_PTR(ret); 5360 5349 5361 5350 } 5362 5351