forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/mtd/ubi/build.c
....@@ -1,20 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) International Business Machines Corp., 2006
34 * Copyright (c) Nokia Corporation, 2007
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13
- * the GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
185 *
196 * Author: Artem Bityutskiy (Битюцкий Артём),
207 * Frank Haverkamp
....@@ -363,9 +350,6 @@
363350 * we still can use 'ubi->ubi_num'.
364351 */
365352 ubi = container_of(dev, struct ubi_device, dev);
366
- ubi = ubi_get_device(ubi->ubi_num);
367
- if (!ubi)
368
- return -ENODEV;
369353
370354 if (attr == &dev_eraseblock_size)
371355 ret = sprintf(buf, "%d\n", ubi->leb_size);
....@@ -394,7 +378,6 @@
394378 else
395379 ret = -EINVAL;
396380
397
- ubi_put_device(ubi);
398381 return ret;
399382 }
400383
....@@ -516,19 +499,40 @@
516499 }
517500
518501 /**
502
+ * ubi_free_volumes_from - free volumes from specific index.
503
+ * @ubi: UBI device description object
504
+ * @from: the start index used for volume free.
505
+ */
506
+static void ubi_free_volumes_from(struct ubi_device *ubi, int from)
507
+{
508
+ int i;
509
+
510
+ for (i = from; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
511
+ if (!ubi->volumes[i])
512
+ continue;
513
+ ubi_eba_replace_table(ubi->volumes[i], NULL);
514
+ ubi_fastmap_destroy_checkmap(ubi->volumes[i]);
515
+ kfree(ubi->volumes[i]);
516
+ ubi->volumes[i] = NULL;
517
+ }
518
+}
519
+
520
+/**
521
+ * ubi_free_all_volumes - free all volumes.
522
+ * @ubi: UBI device description object
523
+ */
524
+void ubi_free_all_volumes(struct ubi_device *ubi)
525
+{
526
+ ubi_free_volumes_from(ubi, 0);
527
+}
528
+
529
+/**
519530 * ubi_free_internal_volumes - free internal volumes.
520531 * @ubi: UBI device description object
521532 */
522533 void ubi_free_internal_volumes(struct ubi_device *ubi)
523534 {
524
- int i;
525
-
526
- for (i = ubi->vtbl_slots;
527
- i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
528
- ubi_eba_replace_table(ubi->volumes[i], NULL);
529
- ubi_fastmap_destroy_checkmap(ubi->volumes[i]);
530
- kfree(ubi->volumes[i]);
531
- }
535
+ ubi_free_volumes_from(ubi, ubi->vtbl_slots);
532536 }
533537
534538 static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024)
....@@ -859,8 +863,11 @@
859863 * Both UBI and UBIFS have been designed for SLC NAND and NOR flashes.
860864 * MLC NAND is different and needs special care, otherwise UBI or UBIFS
861865 * will die soon and you will lose all your data.
866
+ * Relax this rule if the partition we're attaching to operates in SLC
867
+ * mode.
862868 */
863
- if (mtd->type == MTD_MLCNANDFLASH) {
869
+ if (mtd->type == MTD_MLCNANDFLASH &&
870
+ !(mtd->flags & MTD_SLC_ON_MLC_EMULATION)) {
864871 pr_err("ubi: refuse attaching mtd%d - MLC NAND is not supported\n",
865872 mtd->index);
866873 return -EINVAL;
....@@ -969,9 +976,6 @@
969976 goto out_detach;
970977 }
971978
972
- /* Make device "available" before it becomes accessible via sysfs */
973
- ubi_devices[ubi_num] = ubi;
974
-
975979 err = uif_init(ubi);
976980 if (err)
977981 goto out_detach;
....@@ -1016,6 +1020,7 @@
10161020 wake_up_process(ubi->bgt_thread);
10171021 spin_unlock(&ubi->wl_lock);
10181022
1023
+ ubi_devices[ubi_num] = ubi;
10191024 ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
10201025 return ubi_num;
10211026
....@@ -1024,9 +1029,8 @@
10241029 out_uif:
10251030 uif_close(ubi);
10261031 out_detach:
1027
- ubi_devices[ubi_num] = NULL;
10281032 ubi_wl_close(ubi);
1029
- ubi_free_internal_volumes(ubi);
1033
+ ubi_free_all_volumes(ubi);
10301034 vfree(ubi->vtbl);
10311035 out_free:
10321036 vfree(ubi->peb_buf);
....@@ -1172,7 +1176,7 @@
11721176 * MTD device name.
11731177 */
11741178 mtd = get_mtd_device_nm(mtd_dev);
1175
- if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV)
1179
+ if (PTR_ERR(mtd) == -ENODEV)
11761180 /* Probably this is an MTD character device node path */
11771181 mtd = open_mtd_by_chdev(mtd_dev);
11781182 } else
....@@ -1334,8 +1338,10 @@
13341338 switch (*endp) {
13351339 case 'G':
13361340 result *= 1024;
1341
+ fallthrough;
13371342 case 'M':
13381343 result *= 1024;
1344
+ fallthrough;
13391345 case 'K':
13401346 result *= 1024;
13411347 if (endp[1] == 'i' && endp[2] == 'B')
....@@ -1463,3 +1469,4 @@
14631469 MODULE_DESCRIPTION("UBI - Unsorted Block Images");
14641470 MODULE_AUTHOR("Artem Bityutskiy");
14651471 MODULE_LICENSE("GPL");
1472
+MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);