On Thu, Apr 11, 2024 at 11:19:01AM +0800, Zhihao Cheng wrote:
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").
Since ubiblock_init() registers notifier and invokes notification
functions, so we can move it after ubi_init_attach() to fix the problem.
Fixes: 927c145208b0 ("mtd: ubi: attach from device tree")
Signed-off-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
---
drivers/mtd/ubi/build.c | 51 +++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7f95fd7968a8..bc63fbf5e947 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1263,9 +1263,21 @@ static struct mtd_notifier ubi_mtd_notifier = {
.remove = ubi_notify_remove,
};
+static void detach_mtd_devs(int count)
Missing __init to avoid section missmatch.
See also: https://lore.kernel.org/oe-kbuild-all/202404112327.158HJfAw-lkp@xxxxxxxxx/
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ if (ubi_devices[i]) {
+ mutex_lock(&ubi_devices_mutex);
+ ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);
+ mutex_unlock(&ubi_devices_mutex);
+ }
+}