Re: [PATCH] blkcg: avoid free blkcg_root when failed to alloc blkcg policy

2017-08-25 Thread Jens Axboe
On 08/25/2017 09:49 AM, weiping zhang wrote:
> this patch fix two errors, firstly avoid kfree blk_root, secondly not
> free(blkcg) ,if blkcg alloc fail(blkcg == NULL), just unlock that mutex;

Looks good, applied.

-- 
Jens Axboe



[PATCH] blkcg: avoid free blkcg_root when failed to alloc blkcg policy

2017-08-25 Thread weiping zhang
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 
---
 block/blk-cgroup.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 0480892..d3f56ba 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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;
}
}
 
@@ -,8 +,10 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
for (i--; i >= 0; i--)
if (blkcg->cpd[i])
blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
-free_blkcg:
-   kfree(blkcg);
+
+   if (blkcg != _root)
+   kfree(blkcg);
+unlock:
mutex_unlock(_pol_mutex);
return ret;
 }
-- 
2.9.4