Skip to content

Commit dbbca20

Browse files
Tao Cuiaxboe
authored andcommitted
blk-cgroup: fix leaks and online flag on radix_tree_insert failure
When radix_tree_insert() fails in blkg_create(), the error path has two issues: 1. blkg->online is set to true unconditionally, even when the blkg was never fully inserted. Move the assignment inside the success block. 2. The error path calls blkg_put() without first calling percpu_ref_kill(). Because the refcount is still in percpu mode, percpu_ref_put() only does this_cpu_sub() without checking for zero, so blkg_release() is never triggered. This permanently leaks the blkg memory, its percpu iostat, policy data, the parent blkg reference, and the cgroup css reference — the latter preventing the cgroup from ever being destroyed. Fix by replacing blkg_put() with percpu_ref_kill(), matching the pattern used in blkg_destroy(). Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Tao Cui <cuitao@kylinos.cn> Link: https://patch.msgid.link/20260715132407.1469777-1-cui.tao@linux.dev Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c4f4c0f commit dbbca20

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

block/blk-cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,15 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
434434
blkg->pd[i]->online = true;
435435
}
436436
}
437+
blkg->online = true;
437438
}
438-
blkg->online = true;
439439
spin_unlock(&blkcg->lock);
440440

441441
if (!ret)
442442
return blkg;
443443

444444
/* @blkg failed fully initialized, use the usual release path */
445-
blkg_put(blkg);
445+
percpu_ref_kill(&blkg->refcnt);
446446
return ERR_PTR(ret);
447447

448448
err_free_blkg:

0 commit comments

Comments
 (0)