ubi: block: fix memleak in ubiblock_create()
authorLi Nan <linan122@huawei.com>
Fri, 8 Dec 2023 07:46:29 +0000 (15:46 +0800)
committerRichard Weinberger <richard@nod.at>
Sat, 6 Jan 2024 22:52:51 +0000 (23:52 +0100)
If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in
ubiblock_create(), but dev->gd has not been assigned yet at this time, and
'gd' will not be put anymore. Fix it by putting 'gd' directly.

Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/block.c

index 309a42aeaa4cdbbab017252175b18748c91d0cf4..654bd7372cd8c09c69bf7c205a728f263dcc3dfc 100644 (file)
@@ -434,7 +434,7 @@ out_remove_minor:
        list_del(&dev->list);
        idr_remove(&ubiblock_minor_idr, gd->first_minor);
 out_cleanup_disk:
-       put_disk(dev->gd);
+       put_disk(gd);
 out_free_tags:
        blk_mq_free_tag_set(&dev->tag_set);
 out_free_dev: