Commit 496fb780 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

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: default avatarTejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent aaf7c680
...@@ -174,6 +174,7 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg, ...@@ -174,6 +174,7 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
__releases(q->queue_lock) __acquires(q->queue_lock) __releases(q->queue_lock) __acquires(q->queue_lock)
{ {
struct blkcg_gq *blkg; struct blkcg_gq *blkg;
int ret;
WARN_ON_ONCE(!rcu_read_lock_held()); WARN_ON_ONCE(!rcu_read_lock_held());
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
...@@ -186,24 +187,22 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg, ...@@ -186,24 +187,22 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
if (!css_tryget(&blkcg->css)) if (!css_tryget(&blkcg->css))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* /* allocate */
* Allocate and initialize. ret = -ENOMEM;
*/
blkg = blkg_alloc(blkcg, q); blkg = blkg_alloc(blkcg, q);
if (unlikely(!blkg))
/* did alloc fail? */ goto err_put;
if (unlikely(!blkg)) {
blkg = ERR_PTR(-ENOMEM);
goto out;
}
/* insert */ /* insert */
spin_lock(&blkcg->lock); spin_lock(&blkcg->lock);
hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list); hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
list_add(&blkg->q_node, &q->blkg_list); list_add(&blkg->q_node, &q->blkg_list);
spin_unlock(&blkcg->lock); spin_unlock(&blkcg->lock);
out:
return blkg; return blkg;
err_put:
css_put(&blkcg->css);
return ERR_PTR(ret);
} }
struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment