Lines Matching +full:non +full:- +full:gracefully

1 // SPDX-License-Identifier: GPL-2.0+
9 * UBI attaching sub-system.
11 * This sub-system is responsible for attaching MTD devices and it also
16 * objects which are kept in volume RB-tree with root at the @volumes field.
17 * The RB-tree is indexed by the volume ID.
20 * objects are kept in per-volume RB-trees with the root at the corresponding
21 * &struct ubi_ainf_volume object. To put it differently, we keep an RB-tree of
22 * per-volume objects and each of these objects is the root of RB-tree of
23 * per-LEB objects.
32 * UBI protects EC and VID headers with CRC-32 checksums, so it can detect
34 * data with CRC-32, e.g., when it executes the atomic LEB change operation, or
35 * when it moves the contents of a PEB for wear-leveling purposes.
40 * tries to handle them gracefully, without printing too many warnings and
42 * cases - we may lose only the data which were being written to the media just
46 * When UBI detects a corruption (CRC-32 mismatch) in a PEB, and it looks like
59 * the data area does not contain all 0xFFs, and there were no bit-flips or
64 * to just erase this PEB - this is corruption type 1.
65 * o If the data area has bit-flips or data integrity errors (ECC errors on
94 * add_to_list - add physical eraseblock to a list.
119 if (list == &ai->free) { in add_to_list()
121 } else if (list == &ai->erase) { in add_to_list()
123 } else if (list == &ai->alien) { in add_to_list()
125 ai->alien_peb_count += 1; in add_to_list()
129 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in add_to_list()
131 return -ENOMEM; in add_to_list()
133 aeb->pnum = pnum; in add_to_list()
134 aeb->vol_id = vol_id; in add_to_list()
135 aeb->lnum = lnum; in add_to_list()
136 aeb->ec = ec; in add_to_list()
138 list_add(&aeb->u.list, list); in add_to_list()
140 list_add_tail(&aeb->u.list, list); in add_to_list()
145 * add_corrupted - add a corrupted physical eraseblock.
161 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in add_corrupted()
163 return -ENOMEM; in add_corrupted()
165 ai->corr_peb_count += 1; in add_corrupted()
166 aeb->pnum = pnum; in add_corrupted()
167 aeb->ec = ec; in add_corrupted()
168 list_add(&aeb->u.list, &ai->corr); in add_corrupted()
173 * validate_vid_hdr - check volume identifier header.
180 * non-zero if an inconsistency was found and zero if not.
183 * Most of the checks are done in the I/O sub-system. Here we check that the
191 int vol_type = vid_hdr->vol_type; in validate_vid_hdr()
192 int vol_id = be32_to_cpu(vid_hdr->vol_id); in validate_vid_hdr()
193 int used_ebs = be32_to_cpu(vid_hdr->used_ebs); in validate_vid_hdr()
194 int data_pad = be32_to_cpu(vid_hdr->data_pad); in validate_vid_hdr()
196 if (av->leb_count != 0) { in validate_vid_hdr()
205 if (vol_id != av->vol_id) { in validate_vid_hdr()
210 if (av->vol_type == UBI_STATIC_VOLUME) in validate_vid_hdr()
220 if (used_ebs != av->used_ebs) { in validate_vid_hdr()
225 if (data_pad != av->data_pad) { in validate_vid_hdr()
237 return -EINVAL; in validate_vid_hdr()
241 * add_volume - add volume to the attaching information.
258 struct rb_node **p = &ai->volumes.rb_node, *parent = NULL; in add_volume()
260 ubi_assert(vol_id == be32_to_cpu(vid_hdr->vol_id)); in add_volume()
262 /* Walk the volume RB-tree to look if this volume is already present */ in add_volume()
267 if (vol_id == av->vol_id) in add_volume()
270 if (vol_id > av->vol_id) in add_volume()
271 p = &(*p)->rb_left; in add_volume()
273 p = &(*p)->rb_right; in add_volume()
276 /* The volume is absent - add it */ in add_volume()
279 return ERR_PTR(-ENOMEM); in add_volume()
281 av->highest_lnum = av->leb_count = 0; in add_volume()
282 av->vol_id = vol_id; in add_volume()
283 av->root = RB_ROOT; in add_volume()
284 av->used_ebs = be32_to_cpu(vid_hdr->used_ebs); in add_volume()
285 av->data_pad = be32_to_cpu(vid_hdr->data_pad); in add_volume()
286 av->compat = vid_hdr->compat; in add_volume()
287 av->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME in add_volume()
289 if (vol_id > ai->highest_vol_id) in add_volume()
290 ai->highest_vol_id = vol_id; in add_volume()
292 rb_link_node(&av->rb, parent, p); in add_volume()
293 rb_insert_color(&av->rb, &ai->volumes); in add_volume()
294 ai->vols_found += 1; in add_volume()
300 * ubi_compare_lebs - find out which logical eraseblock is newer.
314 * o bit 1 is cleared: no bit-flips were detected in the newer LEB;
315 * o bit 1 is set: bit-flips were detected in the newer LEB;
325 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); in ubi_compare_lebs()
327 if (sqnum2 == aeb->sqnum) { in ubi_compare_lebs()
331 * that times we used 32-bit LEB versions stored in logical in ubi_compare_lebs()
336 ubi_err(ubi, "unsupported on-flash UBI format"); in ubi_compare_lebs()
337 return -EINVAL; in ubi_compare_lebs()
341 second_is_newer = (sqnum2 > aeb->sqnum); in ubi_compare_lebs()
347 * for the first one - we'll need to re-read it from flash. in ubi_compare_lebs()
353 if (!vid_hdr->copy_flag) { in ubi_compare_lebs()
360 if (!aeb->copy_flag) { in ubi_compare_lebs()
369 return -ENOMEM; in ubi_compare_lebs()
371 pnum = aeb->pnum; in ubi_compare_lebs()
380 err = -EIO; in ubi_compare_lebs()
391 len = be32_to_cpu(vid_hdr->data_size); in ubi_compare_lebs()
393 mutex_lock(&ubi->buf_mutex); in ubi_compare_lebs()
394 err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, len); in ubi_compare_lebs()
398 data_crc = be32_to_cpu(vid_hdr->data_crc); in ubi_compare_lebs()
399 crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, len); in ubi_compare_lebs()
410 mutex_unlock(&ubi->buf_mutex); in ubi_compare_lebs()
422 mutex_unlock(&ubi->buf_mutex); in ubi_compare_lebs()
429 * ubi_add_to_av - add used physical eraseblock to the attaching information.
435 * @bitflips: if bit-flips were detected when this physical eraseblock was read
453 vol_id = be32_to_cpu(vid_hdr->vol_id); in ubi_add_to_av()
454 lnum = be32_to_cpu(vid_hdr->lnum); in ubi_add_to_av()
455 sqnum = be64_to_cpu(vid_hdr->sqnum); in ubi_add_to_av()
464 if (ai->max_sqnum < sqnum) in ubi_add_to_av()
465 ai->max_sqnum = sqnum; in ubi_add_to_av()
468 * Walk the RB-tree of logical eraseblocks of volume @vol_id to look in ubi_add_to_av()
471 p = &av->root.rb_node; in ubi_add_to_av()
477 if (lnum != aeb->lnum) { in ubi_add_to_av()
478 if (lnum < aeb->lnum) in ubi_add_to_av()
479 p = &(*p)->rb_left; in ubi_add_to_av()
481 p = &(*p)->rb_right; in ubi_add_to_av()
491 aeb->pnum, aeb->sqnum, aeb->ec); in ubi_add_to_av()
506 if (aeb->sqnum == sqnum && sqnum != 0) { in ubi_add_to_av()
511 return -EINVAL; in ubi_add_to_av()
531 err = add_to_list(ai, aeb->pnum, aeb->vol_id, in ubi_add_to_av()
532 aeb->lnum, aeb->ec, cmp_res & 4, in ubi_add_to_av()
533 &ai->erase); in ubi_add_to_av()
537 aeb->ec = ec; in ubi_add_to_av()
538 aeb->pnum = pnum; in ubi_add_to_av()
539 aeb->vol_id = vol_id; in ubi_add_to_av()
540 aeb->lnum = lnum; in ubi_add_to_av()
541 aeb->scrub = ((cmp_res & 2) || bitflips); in ubi_add_to_av()
542 aeb->copy_flag = vid_hdr->copy_flag; in ubi_add_to_av()
543 aeb->sqnum = sqnum; in ubi_add_to_av()
545 if (av->highest_lnum == lnum) in ubi_add_to_av()
546 av->last_data_size = in ubi_add_to_av()
547 be32_to_cpu(vid_hdr->data_size); in ubi_add_to_av()
556 cmp_res & 4, &ai->erase); in ubi_add_to_av()
569 aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL); in ubi_add_to_av()
571 return -ENOMEM; in ubi_add_to_av()
573 aeb->ec = ec; in ubi_add_to_av()
574 aeb->pnum = pnum; in ubi_add_to_av()
575 aeb->vol_id = vol_id; in ubi_add_to_av()
576 aeb->lnum = lnum; in ubi_add_to_av()
577 aeb->scrub = bitflips; in ubi_add_to_av()
578 aeb->copy_flag = vid_hdr->copy_flag; in ubi_add_to_av()
579 aeb->sqnum = sqnum; in ubi_add_to_av()
581 if (av->highest_lnum <= lnum) { in ubi_add_to_av()
582 av->highest_lnum = lnum; in ubi_add_to_av()
583 av->last_data_size = be32_to_cpu(vid_hdr->data_size); in ubi_add_to_av()
586 av->leb_count += 1; in ubi_add_to_av()
587 rb_link_node(&aeb->u.rb, parent, p); in ubi_add_to_av()
588 rb_insert_color(&aeb->u.rb, &av->root); in ubi_add_to_av()
593 * ubi_find_av - find volume in the attaching information.
604 struct rb_node *p = ai->volumes.rb_node; in ubi_find_av()
609 if (vol_id == av->vol_id) in ubi_find_av()
612 if (vol_id > av->vol_id) in ubi_find_av()
613 p = p->rb_left; in ubi_find_av()
615 p = p->rb_right; in ubi_find_av()
622 * ubi_remove_av - delete attaching information about a volume.
631 dbg_bld("remove attaching information about volume %d", av->vol_id); in ubi_remove_av()
633 while ((rb = rb_first(&av->root))) { in ubi_remove_av()
635 rb_erase(&aeb->u.rb, &av->root); in ubi_remove_av()
636 list_add_tail(&aeb->u.list, &ai->erase); in ubi_remove_av()
639 rb_erase(&av->rb, &ai->volumes); in ubi_remove_av()
641 ai->vols_found -= 1; in ubi_remove_av()
645 * early_erase_peb - erase a physical eraseblock.
653 * initialization stages, when the EBA sub-system had not been yet initialized.
665 * Erase counter overflow. Upgrade UBI and use 64-bit in early_erase_peb()
670 return -EINVAL; in early_erase_peb()
673 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in early_erase_peb()
675 return -ENOMEM; in early_erase_peb()
677 ec_hdr->ec = cpu_to_be64(ec); in early_erase_peb()
691 * ubi_early_get_peb - get a free physical eraseblock.
696 * called on the UBI initialization stages when the wear-leveling sub-system is
710 if (!list_empty(&ai->free)) { in ubi_early_get_peb()
711 aeb = list_entry(ai->free.next, struct ubi_ainf_peb, u.list); in ubi_early_get_peb()
712 list_del(&aeb->u.list); in ubi_early_get_peb()
713 dbg_bld("return free PEB %d, EC %d", aeb->pnum, aeb->ec); in ubi_early_get_peb()
720 * so forth. We don't want to take care about bad eraseblocks here - in ubi_early_get_peb()
723 list_for_each_entry_safe(aeb, tmp_aeb, &ai->erase, u.list) { in ubi_early_get_peb()
724 if (aeb->ec == UBI_UNKNOWN) in ubi_early_get_peb()
725 aeb->ec = ai->mean_ec; in ubi_early_get_peb()
727 err = early_erase_peb(ubi, ai, aeb->pnum, aeb->ec+1); in ubi_early_get_peb()
731 aeb->ec += 1; in ubi_early_get_peb()
732 list_del(&aeb->u.list); in ubi_early_get_peb()
733 dbg_bld("return PEB %d, EC %d", aeb->pnum, aeb->ec); in ubi_early_get_peb()
738 return ERR_PTR(-ENOSPC); in ubi_early_get_peb()
742 * check_corruption - check the data area of PEB.
763 mutex_lock(&ubi->buf_mutex); in check_corruption()
764 memset(ubi->peb_buf, 0x00, ubi->leb_size); in check_corruption()
766 err = ubi_io_read(ubi, ubi->peb_buf, pnum, ubi->leb_start, in check_corruption()
767 ubi->leb_size); in check_corruption()
770 * Bit-flips or integrity errors while reading the data area. in check_corruption()
783 if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size)) in check_corruption()
788 …ubi_err(ubi, "this may be a non-UBI PEB or a severe VID header corruption which requires manual in… in check_corruption()
791 pnum, ubi->leb_start, ubi->leb_size); in check_corruption()
793 ubi->peb_buf, ubi->leb_size, 1); in check_corruption()
797 mutex_unlock(&ubi->buf_mutex); in check_corruption()
802 * scan_peb - scan and process UBI headers of a PEB.
810 * information about this PEB to the corresponding list or RB-tree in the
818 int err, bitflips = 0, vol_id = -1, ec_err = 0; in scan_peb()
827 ai->bad_peb_count += 1; in scan_peb()
841 ai->empty_peb_count += 1; in scan_peb()
843 UBI_UNKNOWN, 0, &ai->erase); in scan_peb()
845 ai->empty_peb_count += 1; in scan_peb()
847 UBI_UNKNOWN, 1, &ai->erase); in scan_peb()
853 * moved and EC be re-created. in scan_peb()
862 return -EINVAL; in scan_peb()
869 if (ech->version != UBI_VERSION) { in scan_peb()
871 UBI_VERSION, (int)ech->version); in scan_peb()
872 return -EINVAL; in scan_peb()
875 ec = be64_to_cpu(ech->ec); in scan_peb()
881 * flash. Upgrade UBI and use 64-bit erase counters in scan_peb()
887 return -EINVAL; in scan_peb()
898 * sequence number, while other PEBs have non-zero sequence in scan_peb()
901 image_seq = be32_to_cpu(ech->image_seq); in scan_peb()
902 if (!ubi->image_seq) in scan_peb()
903 ubi->image_seq = image_seq; in scan_peb()
904 if (image_seq && ubi->image_seq != image_seq) { in scan_peb()
906 image_seq, pnum, ubi->image_seq); in scan_peb()
908 return -EINVAL; in scan_peb()
931 ai->maybe_bad_peb_count += 1; in scan_peb()
959 UBI_UNKNOWN, ec, 1, &ai->erase); in scan_peb()
968 ec, 1, &ai->erase); in scan_peb()
975 UBI_UNKNOWN, ec, 1, &ai->erase); in scan_peb()
978 UBI_UNKNOWN, ec, 0, &ai->free); in scan_peb()
985 return -EINVAL; in scan_peb()
988 vol_id = be32_to_cpu(vidh->vol_id); in scan_peb()
992 *sqnum = be64_to_cpu(vidh->sqnum); in scan_peb()
994 int lnum = be32_to_cpu(vidh->lnum); in scan_peb()
997 switch (vidh->compat) { in scan_peb()
1005 ec, 1, &ai->erase); in scan_peb()
1011 ubi_msg(ubi, "read-only compatible internal volume %d:%d found, switch to read-only mode", in scan_peb()
1013 ubi->ro_mode = 1; in scan_peb()
1020 ec, 0, &ai->alien); in scan_peb()
1028 return -EINVAL; in scan_peb()
1041 ai->ec_sum += ec; in scan_peb()
1042 ai->ec_count += 1; in scan_peb()
1043 if (ec > ai->max_ec) in scan_peb()
1044 ai->max_ec = ec; in scan_peb()
1045 if (ec < ai->min_ec) in scan_peb()
1046 ai->min_ec = ec; in scan_peb()
1053 * late_analysis - analyze the overall situation with PEB.
1061 * should proceed with attaching the MTD device, and %-EINVAL if we should not.
1068 peb_count = ubi->peb_count - ai->bad_peb_count - ai->alien_peb_count; in late_analysis()
1076 if (ai->corr_peb_count) { in late_analysis()
1078 ai->corr_peb_count); in late_analysis()
1080 list_for_each_entry(aeb, &ai->corr, u.list) in late_analysis()
1081 pr_cont(" %d", aeb->pnum); in late_analysis()
1088 if (ai->corr_peb_count >= max_corr) { in late_analysis()
1090 return -EINVAL; in late_analysis()
1094 if (ai->empty_peb_count + ai->maybe_bad_peb_count == peb_count) { in late_analysis()
1096 * All PEBs are empty, or almost all - a couple PEBs look like in late_analysis()
1107 * 2. Flash contains non-UBI data and we do not want to format in late_analysis()
1110 if (ai->maybe_bad_peb_count <= 2) { in late_analysis()
1111 ai->is_empty = 1; in late_analysis()
1113 get_random_bytes(&ubi->image_seq, in late_analysis()
1114 sizeof(ubi->image_seq)); in late_analysis()
1116 ubi_err(ubi, "MTD device is not UBI-formatted and possibly contains non-UBI data - refusing it"); in late_analysis()
1117 return -EINVAL; in late_analysis()
1126 * destroy_av - free volume attaching information.
1135 struct rb_node *this = av->root.rb_node; in destroy_av()
1138 if (this->rb_left) in destroy_av()
1139 this = this->rb_left; in destroy_av()
1140 else if (this->rb_right) in destroy_av()
1141 this = this->rb_right; in destroy_av()
1146 if (this->rb_left == &aeb->u.rb) in destroy_av()
1147 this->rb_left = NULL; in destroy_av()
1149 this->rb_right = NULL; in destroy_av()
1152 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_av()
1159 * destroy_ai - destroy attaching information.
1168 list_for_each_entry_safe(aeb, aeb_tmp, &ai->alien, u.list) { in destroy_ai()
1169 list_del(&aeb->u.list); in destroy_ai()
1170 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1172 list_for_each_entry_safe(aeb, aeb_tmp, &ai->erase, u.list) { in destroy_ai()
1173 list_del(&aeb->u.list); in destroy_ai()
1174 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1176 list_for_each_entry_safe(aeb, aeb_tmp, &ai->corr, u.list) { in destroy_ai()
1177 list_del(&aeb->u.list); in destroy_ai()
1178 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1180 list_for_each_entry_safe(aeb, aeb_tmp, &ai->free, u.list) { in destroy_ai()
1181 list_del(&aeb->u.list); in destroy_ai()
1182 kmem_cache_free(ai->aeb_slab_cache, aeb); in destroy_ai()
1185 /* Destroy the volume RB-tree */ in destroy_ai()
1186 rb = ai->volumes.rb_node; in destroy_ai()
1188 if (rb->rb_left) in destroy_ai()
1189 rb = rb->rb_left; in destroy_ai()
1190 else if (rb->rb_right) in destroy_ai()
1191 rb = rb->rb_right; in destroy_ai()
1197 if (rb->rb_left == &av->rb) in destroy_ai()
1198 rb->rb_left = NULL; in destroy_ai()
1200 rb->rb_right = NULL; in destroy_ai()
1207 kmem_cache_destroy(ai->aeb_slab_cache); in destroy_ai()
1213 * scan_all - scan entire MTD device.
1230 err = -ENOMEM; in scan_all()
1232 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in scan_all()
1240 for (pnum = start; pnum < ubi->peb_count; pnum++) { in scan_all()
1252 if (ai->ec_count) in scan_all()
1253 ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); in scan_all()
1263 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in scan_all()
1264 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) in scan_all()
1265 if (aeb->ec == UBI_UNKNOWN) in scan_all()
1266 aeb->ec = ai->mean_ec; in scan_all()
1269 list_for_each_entry(aeb, &ai->free, u.list) { in scan_all()
1270 if (aeb->ec == UBI_UNKNOWN) in scan_all()
1271 aeb->ec = ai->mean_ec; in scan_all()
1274 list_for_each_entry(aeb, &ai->corr, u.list) in scan_all()
1275 if (aeb->ec == UBI_UNKNOWN) in scan_all()
1276 aeb->ec = ai->mean_ec; in scan_all()
1278 list_for_each_entry(aeb, &ai->erase, u.list) in scan_all()
1279 if (aeb->ec == UBI_UNKNOWN) in scan_all()
1280 aeb->ec = ai->mean_ec; in scan_all()
1306 INIT_LIST_HEAD(&ai->corr); in alloc_ai()
1307 INIT_LIST_HEAD(&ai->free); in alloc_ai()
1308 INIT_LIST_HEAD(&ai->erase); in alloc_ai()
1309 INIT_LIST_HEAD(&ai->alien); in alloc_ai()
1310 ai->volumes = RB_ROOT; in alloc_ai()
1311 ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache", in alloc_ai()
1314 if (!ai->aeb_slab_cache) { in alloc_ai()
1325 * scan_fastmap - try to find a fastmap and attach from it.
1336 int err, pnum, fm_anchor = -1; in scan_fast()
1339 err = -ENOMEM; in scan_fast()
1341 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in scan_fast()
1350 int vol_id = -1; in scan_fast()
1351 unsigned long long sqnum = -1; in scan_fast()
1374 return -ENOMEM; in scan_fast()
1389 * ubi_attach - attach an MTD device.
1391 * @force_scan: if set to non-zero attach by scanning
1403 return -ENOMEM; in ubi_attach()
1407 if ((int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) <= UBI_FM_MAX_START) { in ubi_attach()
1408 ubi->fm_disabled = 1; in ubi_attach()
1421 return -ENOMEM; in ubi_attach()
1435 ubi->bad_peb_count = ai->bad_peb_count; in ubi_attach()
1436 ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; in ubi_attach()
1437 ubi->corr_peb_count = ai->corr_peb_count; in ubi_attach()
1438 ubi->max_ec = ai->max_ec; in ubi_attach()
1439 ubi->mean_ec = ai->mean_ec; in ubi_attach()
1440 dbg_gen("max. sequence number: %llu", ai->max_sqnum); in ubi_attach()
1455 if (ubi->fm && ubi_dbg_chk_fastmap(ubi)) { in ubi_attach()
1460 err = -ENOMEM; in ubi_attach()
1485 vfree(ubi->vtbl); in ubi_attach()
1492 * self_check_ai - check the attaching information.
1513 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in self_check_ai()
1520 if (ai->is_empty) { in self_check_ai()
1525 if (av->vol_id < 0 || av->highest_lnum < 0 || in self_check_ai()
1526 av->leb_count < 0 || av->vol_type < 0 || av->used_ebs < 0 || in self_check_ai()
1527 av->data_pad < 0 || av->last_data_size < 0) { in self_check_ai()
1532 if (av->vol_id >= UBI_MAX_VOLUMES && in self_check_ai()
1533 av->vol_id < UBI_INTERNAL_VOL_START) { in self_check_ai()
1538 if (av->vol_id > ai->highest_vol_id) { in self_check_ai()
1540 ai->highest_vol_id, av->vol_id); in self_check_ai()
1544 if (av->vol_type != UBI_DYNAMIC_VOLUME && in self_check_ai()
1545 av->vol_type != UBI_STATIC_VOLUME) { in self_check_ai()
1550 if (av->data_pad > ubi->leb_size / 2) { in self_check_ai()
1556 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) { in self_check_ai()
1562 if (aeb->pnum < 0 || aeb->ec < 0) { in self_check_ai()
1567 if (aeb->ec < ai->min_ec) { in self_check_ai()
1568 ubi_err(ubi, "bad ai->min_ec (%d), %d found", in self_check_ai()
1569 ai->min_ec, aeb->ec); in self_check_ai()
1573 if (aeb->ec > ai->max_ec) { in self_check_ai()
1574 ubi_err(ubi, "bad ai->max_ec (%d), %d found", in self_check_ai()
1575 ai->max_ec, aeb->ec); in self_check_ai()
1579 if (aeb->pnum >= ubi->peb_count) { in self_check_ai()
1581 aeb->pnum, ubi->peb_count); in self_check_ai()
1585 if (av->vol_type == UBI_STATIC_VOLUME) { in self_check_ai()
1586 if (aeb->lnum >= av->used_ebs) { in self_check_ai()
1591 if (av->used_ebs != 0) { in self_check_ai()
1592 ubi_err(ubi, "non-zero used_ebs"); in self_check_ai()
1597 if (aeb->lnum > av->highest_lnum) { in self_check_ai()
1603 if (av->leb_count != leb_count) { in self_check_ai()
1614 if (aeb->lnum != av->highest_lnum) { in self_check_ai()
1620 if (vols_found != ai->vols_found) { in self_check_ai()
1621 ubi_err(ubi, "bad ai->vols_found %d, should be %d", in self_check_ai()
1622 ai->vols_found, vols_found); in self_check_ai()
1627 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) { in self_check_ai()
1629 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) { in self_check_ai()
1636 err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidh, 1); in self_check_ai()
1641 err = -EIO; in self_check_ai()
1645 vol_type = vidh->vol_type == UBI_VID_DYNAMIC ? in self_check_ai()
1647 if (av->vol_type != vol_type) { in self_check_ai()
1652 if (aeb->sqnum != be64_to_cpu(vidh->sqnum)) { in self_check_ai()
1653 ubi_err(ubi, "bad sqnum %llu", aeb->sqnum); in self_check_ai()
1657 if (av->vol_id != be32_to_cpu(vidh->vol_id)) { in self_check_ai()
1658 ubi_err(ubi, "bad vol_id %d", av->vol_id); in self_check_ai()
1662 if (av->compat != vidh->compat) { in self_check_ai()
1663 ubi_err(ubi, "bad compat %d", vidh->compat); in self_check_ai()
1667 if (aeb->lnum != be32_to_cpu(vidh->lnum)) { in self_check_ai()
1668 ubi_err(ubi, "bad lnum %d", aeb->lnum); in self_check_ai()
1672 if (av->used_ebs != be32_to_cpu(vidh->used_ebs)) { in self_check_ai()
1673 ubi_err(ubi, "bad used_ebs %d", av->used_ebs); in self_check_ai()
1677 if (av->data_pad != be32_to_cpu(vidh->data_pad)) { in self_check_ai()
1678 ubi_err(ubi, "bad data_pad %d", av->data_pad); in self_check_ai()
1686 if (av->highest_lnum != be32_to_cpu(vidh->lnum)) { in self_check_ai()
1687 ubi_err(ubi, "bad highest_lnum %d", av->highest_lnum); in self_check_ai()
1691 if (av->last_data_size != be32_to_cpu(vidh->data_size)) { in self_check_ai()
1693 av->last_data_size); in self_check_ai()
1702 buf = kzalloc(ubi->peb_count, GFP_KERNEL); in self_check_ai()
1704 return -ENOMEM; in self_check_ai()
1706 for (pnum = 0; pnum < ubi->peb_count; pnum++) { in self_check_ai()
1715 ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) in self_check_ai()
1716 ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) in self_check_ai()
1717 buf[aeb->pnum] = 1; in self_check_ai()
1719 list_for_each_entry(aeb, &ai->free, u.list) in self_check_ai()
1720 buf[aeb->pnum] = 1; in self_check_ai()
1722 list_for_each_entry(aeb, &ai->corr, u.list) in self_check_ai()
1723 buf[aeb->pnum] = 1; in self_check_ai()
1725 list_for_each_entry(aeb, &ai->erase, u.list) in self_check_ai()
1726 buf[aeb->pnum] = 1; in self_check_ai()
1728 list_for_each_entry(aeb, &ai->alien, u.list) in self_check_ai()
1729 buf[aeb->pnum] = 1; in self_check_ai()
1732 for (pnum = 0; pnum < ubi->peb_count; pnum++) in self_check_ai()
1744 ubi_err(ubi, "bad attaching information about LEB %d", aeb->lnum); in self_check_ai()
1750 ubi_err(ubi, "bad attaching information about volume %d", av->vol_id); in self_check_ai()
1755 ubi_err(ubi, "bad attaching information about volume %d", av->vol_id); in self_check_ai()
1761 return -EINVAL; in self_check_ai()