cgroup: fix harmless bugs in cgroup_load_subsys() fail path and cgroup_unload_subsys()
authorTejun Heo <tj@kernel.org>
Mon, 19 Nov 2012 16:13:37 +0000 (08:13 -0800)
committerTejun Heo <tj@kernel.org>
Mon, 19 Nov 2012 16:13:37 +0000 (08:13 -0800)
* If idr init fails, cgroup_load_subsys() cleared dummytop->subsys[]
  before calilng ->destroy() making CSS inaccessible to the callback,
  and didn't unlink ss->sibling.  As no modular controller uses
  ->use_id, this doesn't cause any actual problems.

* cgroup_unload_subsys() was forgetting to free idr, call
  ->pre_destroy() and clear ->active.  As there currently is no
  modular controller which uses ->use_id, ->pre_destroy() or ->active,
  this doesn't cause any actual problems.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
kernel/cgroup.c

index 09751657abdc17f235675c187d925afdd7da9bc2..5679cb1ce43f0d0ddf462823d0f071744a148c33 100644 (file)
@@ -4420,9 +4420,10 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
        if (ss->use_id) {
                int ret = cgroup_init_idr(ss, css);
                if (ret) {
-                       dummytop->subsys[ss->subsys_id] = NULL;
                        ss->destroy(dummytop);
+                       dummytop->subsys[ss->subsys_id] = NULL;
                        subsys[ss->subsys_id] = NULL;
+                       list_del_init(&ss->sibling);
                        mutex_unlock(&cgroup_mutex);
                        return ret;
                }
@@ -4490,7 +4491,19 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
         */
        BUG_ON(ss->root != &rootnode);
 
+       /* ->pre_destroy() should be called outside cgroup_mutex for now */
+       if (ss->pre_destroy)
+               ss->pre_destroy(dummytop);
+
        mutex_lock(&cgroup_mutex);
+
+       ss->active = 0;
+
+       if (ss->use_id) {
+               idr_remove_all(&ss->idr);
+               idr_destroy(&ss->idr);
+       }
+
        /* deassign the subsys_id */
        subsys[ss->subsys_id] = NULL;