blk-cgroup: fix freeing NULL blkg in blkg_create
authorChristoph Hellwig <hch@lst.de>
Mon, 6 Feb 2023 15:02:01 +0000 (16:02 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 6 Feb 2023 15:43:23 +0000 (08:43 -0700)
new_blkg can be NULL if the caller didn't pass in a pre-allocated blkg.
Don't try to free it in that case.

Fixes: 27b642b07a4a ("blk-cgroup: simplify blkg freeing from initialization failure paths")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20230206150201.3438972-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c

index 8faeca6022bea0e9598f866d5c5bd9e8ceeea038..c46778d1f3c27de10c4ccc359760ec24b74ff335 100644 (file)
@@ -383,7 +383,8 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
 err_put_css:
        css_put(&blkcg->css);
 err_free_blkg:
-       blkg_free(new_blkg);
+       if (new_blkg)
+               blkg_free(new_blkg);
        return ERR_PTR(ret);
 }