When radix_tree_insert() fails in blkg_create(), the error path calls blkg_put() to release the blkg. This was correct when blkg->refcnt was an atomic_t: blkg_put() dropped it to 0 and triggered the release path. But commit 7fcf2b033b84 ("blkcg: change blkg reference counting to use percpu_ref") switched refcnt to a percpu_ref. In percpu mode percpu_ref_put() never checks for zero, so the release callback is never invoked. This blkg is on neither blkcg->blkg_list nor queue->blkg_list, so blkg_destroy_all() / blkcg_destroy_blkgs() can never reach it to call blkg_destroy()->percpu_ref_kill() either, cause the leak. Fix it by killing the percpu_ref instead, which switches it to atomic mode and drops the initial ref. Fixes: 7fcf2b033b84 ("blkcg: change blkg reference counting to use percpu_ref") Signed-off-by: Zizhi Wo Signed-off-by: Zizhi Wo --- block/blk-cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index bc63bd220865..6386fe413994 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -437,11 +437,11 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk, if (!ret) return blkg; /* @blkg failed fully initialized, use the usual release path */ - blkg_put(blkg); + percpu_ref_kill(&blkg->refcnt); return ERR_PTR(ret); err_put_css: css_put(&blkcg->css); err_free_blkg: -- 2.52.0