Skip to content

Commit

Permalink
cgroup: fix idr leak for the first cgroup root
Browse files Browse the repository at this point in the history
The valid cgroup hierarchy ID range includes 0, so we can't filter for
positive numbers when freeing it, or it'll leak the first ID. No big
deal, just disruptive when reading the code.

The ID is freed during error handling and when the reference count
hits zero, so the double-free test is not necessary; remove it.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Johannes Weiner authored and Tejun Heo committed Jun 17, 2016
1 parent db06d75 commit 8c8a550
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
@@ -1158,18 +1158,12 @@ static void cgroup_exit_root_id(struct cgroup_root *root)
{
lockdep_assert_held(&cgroup_mutex);

if (root->hierarchy_id) {
idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
root->hierarchy_id = 0;
}
idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
}

static void cgroup_free_root(struct cgroup_root *root)
{
if (root) {
/* hierarchy ID should already have been released */
WARN_ON_ONCE(root->hierarchy_id);

idr_destroy(&root->cgroup_idr);
kfree(root);
}

0 comments on commit 8c8a550

Please sign in to comment.