[PATCH 2/2] ubi: ubi_init: Fix missed ubiblock cleanup in error handling path

From: Zhihao Cheng
Date: Wed Apr 10 2024 - 03:49:28 EST


The ubiblock_init called by ubi_init will register device number, but
device number is not released in error handling path of ubi_init when
ubi is loaded by inserting module (eg. attaching failure), which leads
to subsequent ubi_init calls failed by running out of device number
(dmesg shows that "__register_blkdev: failed to get major for ubiblock").
Fix it by invoking ubiblock_exit() in corresponding error handling path.

Fixes: 927c145208b0 ("mtd: ubi: attach from device tree")
Signed-off-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
---
drivers/mtd/ubi/build.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7f95fd7968a8..354517194099 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1380,12 +1380,13 @@ static int __init ubi_init(void)
if (ubi_is_module()) {
err = ubi_init_attach();
if (err)
- goto out_mtd_notifier;
+ goto out_block_exit;
}

return 0;

-out_mtd_notifier:
+out_block_exit:
+ ubiblock_exit();
unregister_mtd_user(&ubi_mtd_notifier);
out_debugfs:
ubi_debugfs_exit();
--
2.39.2