blkcg: avoid free blkcg_root when failed to alloc blkcg policy
authorweiping zhang <zhangweiping@didichuxing.com>
Fri, 25 Aug 2017 15:49:32 +0000 (23:49 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 25 Aug 2017 19:51:07 +0000 (13:51 -0600)
this patch fix two errors, firstly avoid kfree blk_root, secondly not
free(blkcg) ,if blkcg alloc fail(blkcg == NULL), just unlock that mutex;

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c

index 0480892e97e501807a7f14f843eb549719f33c81..d3f56baee9366220d13db3cc8668ae1a7a1c1994 100644 (file)
@@ -1067,7 +1067,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
                blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
                if (!blkcg) {
                        ret = ERR_PTR(-ENOMEM);
-                       goto free_blkcg;
+                       goto unlock;
                }
        }
 
@@ -1111,8 +1111,10 @@ free_pd_blkcg:
        for (i--; i >= 0; i--)
                if (blkcg->cpd[i])
                        blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
-free_blkcg:
-       kfree(blkcg);
+
+       if (blkcg != &blkcg_root)
+               kfree(blkcg);
+unlock:
        mutex_unlock(&blkcg_pol_mutex);
        return ret;
 }