Skip to content

Commit 994b783

Browse files
htejunaxboe
authored andcommitted
blkcg: use blkg_free() in blkcg_init_queue() failure path
When blkcg_init_queue() fails midway after creating a new blkg, it performs kfree() directly; however, this doesn't free the policy data areas. Make it use blkg_free() instead. In turn, blkg_free() is updated to handle root request_list special case. While this fixes a possible memory leak, it's on an unlikely failure path of an already cold path and the size leaked per occurrence is miniscule too. I don't think it needs to be tagged for -stable. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 401efbf commit 994b783

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

block/blk-cgroup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static void blkg_free(struct blkcg_gq *blkg)
7070
for (i = 0; i < BLKCG_MAX_POLS; i++)
7171
kfree(blkg->pd[i]);
7272

73-
blk_exit_rl(&blkg->rl);
73+
if (blkg->blkcg != &blkcg_root)
74+
blk_exit_rl(&blkg->rl);
7475
kfree(blkg);
7576
}
7677

@@ -938,7 +939,7 @@ int blkcg_init_queue(struct request_queue *q)
938939
radix_tree_preload_end();
939940

940941
if (IS_ERR(blkg)) {
941-
kfree(new_blkg);
942+
blkg_free(new_blkg);
942943
return PTR_ERR(blkg);
943944
}
944945

0 commit comments

Comments
 (0)