summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-04-19 16:29:23 -0700
committerJens Axboe <axboe@kernel.dk>2012-04-20 10:06:40 +0200
commit496fb7806d616185a46865a4f3a20ef19dc6c7e3 (patch)
treea200e6825be55f6d0ed411ec32dc16244f488fd9 /block
parentaaf7c680682f1999ef2e574f743c45d1674a8b8a (diff)
blkcg: fix blkcg->css ref leak in __blkg_lookup_create()
__blkg_lookup_create() leaked blkcg->css ref if blkg allocation failed. Fix it. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/blk-cgroup.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 82283859727e..30a7a9c58b38 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -174,6 +174,7 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
__releases(q->queue_lock) __acquires(q->queue_lock)
{
struct blkcg_gq *blkg;
+ int ret;
WARN_ON_ONCE(!rcu_read_lock_held());
lockdep_assert_held(q->queue_lock);
@@ -186,24 +187,22 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
if (!css_tryget(&blkcg->css))
return ERR_PTR(-EINVAL);
- /*
- * Allocate and initialize.
- */
+ /* allocate */
+ ret = -ENOMEM;
blkg = blkg_alloc(blkcg, q);
-
- /* did alloc fail? */
- if (unlikely(!blkg)) {
- blkg = ERR_PTR(-ENOMEM);
- goto out;
- }
+ if (unlikely(!blkg))
+ goto err_put;
/* insert */
spin_lock(&blkcg->lock);
hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
list_add(&blkg->q_node, &q->blkg_list);
spin_unlock(&blkcg->lock);
-out:
return blkg;
+
+err_put:
+ css_put(&blkcg->css);
+ return ERR_PTR(ret);
}
struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,