0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 #include <linux/crc32.h>
0049 #include <linux/err.h>
0050 #include <linux/slab.h>
0051 #include <asm/div64.h>
0052 #include "ubi.h"
0053
0054 static void self_vtbl_check(const struct ubi_device *ubi);
0055
0056
0057 static struct ubi_vtbl_record empty_vtbl_record;
0058
0059
0060
0061
0062
0063 static int ubi_update_layout_vol(struct ubi_device *ubi)
0064 {
0065 struct ubi_volume *layout_vol;
0066 int i, err;
0067
0068 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
0069 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
0070 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
0071 ubi->vtbl_size);
0072 if (err)
0073 return err;
0074 }
0075
0076 return 0;
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
0091 struct ubi_vtbl_record *vtbl_rec)
0092 {
0093 int err;
0094 uint32_t crc;
0095
0096 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);
0097
0098 if (!vtbl_rec)
0099 vtbl_rec = &empty_vtbl_record;
0100 else {
0101 crc = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC);
0102 vtbl_rec->crc = cpu_to_be32(crc);
0103 }
0104
0105 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
0106 err = ubi_update_layout_vol(ubi);
0107
0108 self_vtbl_check(ubi);
0109 return err ? err : 0;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
0122 struct list_head *rename_list)
0123 {
0124 struct ubi_rename_entry *re;
0125
0126 list_for_each_entry(re, rename_list, list) {
0127 uint32_t crc;
0128 struct ubi_volume *vol = re->desc->vol;
0129 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id];
0130
0131 if (re->remove) {
0132 memcpy(vtbl_rec, &empty_vtbl_record,
0133 sizeof(struct ubi_vtbl_record));
0134 continue;
0135 }
0136
0137 vtbl_rec->name_len = cpu_to_be16(re->new_name_len);
0138 memcpy(vtbl_rec->name, re->new_name, re->new_name_len);
0139 memset(vtbl_rec->name + re->new_name_len, 0,
0140 UBI_VOL_NAME_MAX + 1 - re->new_name_len);
0141 crc = crc32(UBI_CRC32_INIT, vtbl_rec,
0142 UBI_VTBL_RECORD_SIZE_CRC);
0143 vtbl_rec->crc = cpu_to_be32(crc);
0144 }
0145
0146 return ubi_update_layout_vol(ubi);
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 static int vtbl_check(const struct ubi_device *ubi,
0158 const struct ubi_vtbl_record *vtbl)
0159 {
0160 int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len;
0161 int upd_marker, err;
0162 uint32_t crc;
0163 const char *name;
0164
0165 for (i = 0; i < ubi->vtbl_slots; i++) {
0166 cond_resched();
0167
0168 reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
0169 alignment = be32_to_cpu(vtbl[i].alignment);
0170 data_pad = be32_to_cpu(vtbl[i].data_pad);
0171 upd_marker = vtbl[i].upd_marker;
0172 vol_type = vtbl[i].vol_type;
0173 name_len = be16_to_cpu(vtbl[i].name_len);
0174 name = &vtbl[i].name[0];
0175
0176 crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC);
0177 if (be32_to_cpu(vtbl[i].crc) != crc) {
0178 ubi_err(ubi, "bad CRC at record %u: %#08x, not %#08x",
0179 i, crc, be32_to_cpu(vtbl[i].crc));
0180 ubi_dump_vtbl_record(&vtbl[i], i);
0181 return 1;
0182 }
0183
0184 if (reserved_pebs == 0) {
0185 if (memcmp(&vtbl[i], &empty_vtbl_record,
0186 UBI_VTBL_RECORD_SIZE)) {
0187 err = 2;
0188 goto bad;
0189 }
0190 continue;
0191 }
0192
0193 if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 ||
0194 name_len < 0) {
0195 err = 3;
0196 goto bad;
0197 }
0198
0199 if (alignment > ubi->leb_size || alignment == 0) {
0200 err = 4;
0201 goto bad;
0202 }
0203
0204 n = alignment & (ubi->min_io_size - 1);
0205 if (alignment != 1 && n) {
0206 err = 5;
0207 goto bad;
0208 }
0209
0210 n = ubi->leb_size % alignment;
0211 if (data_pad != n) {
0212 ubi_err(ubi, "bad data_pad, has to be %d", n);
0213 err = 6;
0214 goto bad;
0215 }
0216
0217 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) {
0218 err = 7;
0219 goto bad;
0220 }
0221
0222 if (upd_marker != 0 && upd_marker != 1) {
0223 err = 8;
0224 goto bad;
0225 }
0226
0227 if (reserved_pebs > ubi->good_peb_count) {
0228 ubi_err(ubi, "too large reserved_pebs %d, good PEBs %d",
0229 reserved_pebs, ubi->good_peb_count);
0230 err = 9;
0231 goto bad;
0232 }
0233
0234 if (name_len > UBI_VOL_NAME_MAX) {
0235 err = 10;
0236 goto bad;
0237 }
0238
0239 if (name[0] == '\0') {
0240 err = 11;
0241 goto bad;
0242 }
0243
0244 if (name_len != strnlen(name, name_len + 1)) {
0245 err = 12;
0246 goto bad;
0247 }
0248 }
0249
0250
0251 for (i = 0; i < ubi->vtbl_slots - 1; i++) {
0252 for (n = i + 1; n < ubi->vtbl_slots; n++) {
0253 int len1 = be16_to_cpu(vtbl[i].name_len);
0254 int len2 = be16_to_cpu(vtbl[n].name_len);
0255
0256 if (len1 > 0 && len1 == len2 &&
0257 !strncmp(vtbl[i].name, vtbl[n].name, len1)) {
0258 ubi_err(ubi, "volumes %d and %d have the same name \"%s\"",
0259 i, n, vtbl[i].name);
0260 ubi_dump_vtbl_record(&vtbl[i], i);
0261 ubi_dump_vtbl_record(&vtbl[n], n);
0262 return -EINVAL;
0263 }
0264 }
0265 }
0266
0267 return 0;
0268
0269 bad:
0270 ubi_err(ubi, "volume table check failed: record %d, error %d", i, err);
0271 ubi_dump_vtbl_record(&vtbl[i], i);
0272 return -EINVAL;
0273 }
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai,
0286 int copy, void *vtbl)
0287 {
0288 int err, tries = 0;
0289 struct ubi_vid_io_buf *vidb;
0290 struct ubi_vid_hdr *vid_hdr;
0291 struct ubi_ainf_peb *new_aeb;
0292
0293 dbg_gen("create volume table (copy #%d)", copy + 1);
0294
0295 vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
0296 if (!vidb)
0297 return -ENOMEM;
0298
0299 vid_hdr = ubi_get_vid_hdr(vidb);
0300
0301 retry:
0302 new_aeb = ubi_early_get_peb(ubi, ai);
0303 if (IS_ERR(new_aeb)) {
0304 err = PTR_ERR(new_aeb);
0305 goto out_free;
0306 }
0307
0308 vid_hdr->vol_type = UBI_LAYOUT_VOLUME_TYPE;
0309 vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID);
0310 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
0311 vid_hdr->data_size = vid_hdr->used_ebs =
0312 vid_hdr->data_pad = cpu_to_be32(0);
0313 vid_hdr->lnum = cpu_to_be32(copy);
0314 vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum);
0315
0316
0317 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vidb);
0318 if (err)
0319 goto write_error;
0320
0321
0322 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
0323 if (err)
0324 goto write_error;
0325
0326
0327
0328
0329
0330 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
0331 ubi_free_aeb(ai, new_aeb);
0332 ubi_free_vid_buf(vidb);
0333 return err;
0334
0335 write_error:
0336 if (err == -EIO && ++tries <= 5) {
0337
0338
0339
0340
0341 list_add(&new_aeb->u.list, &ai->erase);
0342 goto retry;
0343 }
0344 ubi_free_aeb(ai, new_aeb);
0345 out_free:
0346 ubi_free_vid_buf(vidb);
0347 return err;
0348
0349 }
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
0362 struct ubi_attach_info *ai,
0363 struct ubi_ainf_volume *av)
0364 {
0365 int err;
0366 struct rb_node *rb;
0367 struct ubi_ainf_peb *aeb;
0368 struct ubi_vtbl_record *leb[UBI_LAYOUT_VOLUME_EBS] = { NULL, NULL };
0369 int leb_corrupted[UBI_LAYOUT_VOLUME_EBS] = {1, 1};
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396 dbg_gen("check layout volume");
0397
0398
0399 ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) {
0400 leb[aeb->lnum] = vzalloc(ubi->vtbl_size);
0401 if (!leb[aeb->lnum]) {
0402 err = -ENOMEM;
0403 goto out_free;
0404 }
0405
0406 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0,
0407 ubi->vtbl_size);
0408 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err))
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419 aeb->scrub = 1;
0420 else if (err)
0421 goto out_free;
0422 }
0423
0424 err = -EINVAL;
0425 if (leb[0]) {
0426 leb_corrupted[0] = vtbl_check(ubi, leb[0]);
0427 if (leb_corrupted[0] < 0)
0428 goto out_free;
0429 }
0430
0431 if (!leb_corrupted[0]) {
0432
0433 if (leb[1])
0434 leb_corrupted[1] = memcmp(leb[0], leb[1],
0435 ubi->vtbl_size);
0436 if (leb_corrupted[1]) {
0437 ubi_warn(ubi, "volume table copy #2 is corrupted");
0438 err = create_vtbl(ubi, ai, 1, leb[0]);
0439 if (err)
0440 goto out_free;
0441 ubi_msg(ubi, "volume table was restored");
0442 }
0443
0444
0445 vfree(leb[1]);
0446 return leb[0];
0447 } else {
0448
0449 if (leb[1]) {
0450 leb_corrupted[1] = vtbl_check(ubi, leb[1]);
0451 if (leb_corrupted[1] < 0)
0452 goto out_free;
0453 }
0454 if (leb_corrupted[1]) {
0455
0456 ubi_err(ubi, "both volume tables are corrupted");
0457 goto out_free;
0458 }
0459
0460 ubi_warn(ubi, "volume table copy #1 is corrupted");
0461 err = create_vtbl(ubi, ai, 0, leb[1]);
0462 if (err)
0463 goto out_free;
0464 ubi_msg(ubi, "volume table was restored");
0465
0466 vfree(leb[0]);
0467 return leb[1];
0468 }
0469
0470 out_free:
0471 vfree(leb[0]);
0472 vfree(leb[1]);
0473 return ERR_PTR(err);
0474 }
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484 static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
0485 struct ubi_attach_info *ai)
0486 {
0487 int i;
0488 struct ubi_vtbl_record *vtbl;
0489
0490 vtbl = vzalloc(ubi->vtbl_size);
0491 if (!vtbl)
0492 return ERR_PTR(-ENOMEM);
0493
0494 for (i = 0; i < ubi->vtbl_slots; i++)
0495 memcpy(&vtbl[i], &empty_vtbl_record, UBI_VTBL_RECORD_SIZE);
0496
0497 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
0498 int err;
0499
0500 err = create_vtbl(ubi, ai, i, vtbl);
0501 if (err) {
0502 vfree(vtbl);
0503 return ERR_PTR(err);
0504 }
0505 }
0506
0507 return vtbl;
0508 }
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520 static int init_volumes(struct ubi_device *ubi,
0521 const struct ubi_attach_info *ai,
0522 const struct ubi_vtbl_record *vtbl)
0523 {
0524 int i, err, reserved_pebs = 0;
0525 struct ubi_ainf_volume *av;
0526 struct ubi_volume *vol;
0527
0528 for (i = 0; i < ubi->vtbl_slots; i++) {
0529 cond_resched();
0530
0531 if (be32_to_cpu(vtbl[i].reserved_pebs) == 0)
0532 continue;
0533
0534 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
0535 if (!vol)
0536 return -ENOMEM;
0537
0538 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
0539 vol->alignment = be32_to_cpu(vtbl[i].alignment);
0540 vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
0541 vol->upd_marker = vtbl[i].upd_marker;
0542 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
0543 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
0544 vol->name_len = be16_to_cpu(vtbl[i].name_len);
0545 vol->usable_leb_size = ubi->leb_size - vol->data_pad;
0546 memcpy(vol->name, vtbl[i].name, vol->name_len);
0547 vol->name[vol->name_len] = '\0';
0548 vol->vol_id = i;
0549
0550 if (vtbl[i].flags & UBI_VTBL_SKIP_CRC_CHECK_FLG)
0551 vol->skip_check = 1;
0552
0553 if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) {
0554
0555 if (ubi->autoresize_vol_id != -1) {
0556 ubi_err(ubi, "more than one auto-resize volume (%d and %d)",
0557 ubi->autoresize_vol_id, i);
0558 kfree(vol);
0559 return -EINVAL;
0560 }
0561
0562 ubi->autoresize_vol_id = i;
0563 }
0564
0565 ubi_assert(!ubi->volumes[i]);
0566 ubi->volumes[i] = vol;
0567 ubi->vol_count += 1;
0568 vol->ubi = ubi;
0569 reserved_pebs += vol->reserved_pebs;
0570
0571
0572
0573
0574
0575
0576
0577 err = ubi_fastmap_init_checkmap(vol, ubi->peb_count);
0578 if (err)
0579 return err;
0580
0581
0582
0583
0584
0585 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
0586 vol->used_ebs = vol->reserved_pebs;
0587 vol->last_eb_bytes = vol->usable_leb_size;
0588 vol->used_bytes =
0589 (long long)vol->used_ebs * vol->usable_leb_size;
0590 continue;
0591 }
0592
0593
0594 av = ubi_find_av(ai, i);
0595 if (!av || !av->leb_count) {
0596
0597
0598
0599
0600
0601
0602
0603
0604 continue;
0605 }
0606
0607 if (av->leb_count != av->used_ebs) {
0608
0609
0610
0611
0612 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted",
0613 av->vol_id, av->used_ebs - av->leb_count);
0614 vol->corrupted = 1;
0615 continue;
0616 }
0617
0618 vol->used_ebs = av->used_ebs;
0619 vol->used_bytes =
0620 (long long)(vol->used_ebs - 1) * vol->usable_leb_size;
0621 vol->used_bytes += av->last_data_size;
0622 vol->last_eb_bytes = av->last_data_size;
0623 }
0624
0625
0626 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
0627 if (!vol)
0628 return -ENOMEM;
0629
0630 vol->reserved_pebs = UBI_LAYOUT_VOLUME_EBS;
0631 vol->alignment = UBI_LAYOUT_VOLUME_ALIGN;
0632 vol->vol_type = UBI_DYNAMIC_VOLUME;
0633 vol->name_len = sizeof(UBI_LAYOUT_VOLUME_NAME) - 1;
0634 memcpy(vol->name, UBI_LAYOUT_VOLUME_NAME, vol->name_len + 1);
0635 vol->usable_leb_size = ubi->leb_size;
0636 vol->used_ebs = vol->reserved_pebs;
0637 vol->last_eb_bytes = vol->reserved_pebs;
0638 vol->used_bytes =
0639 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad);
0640 vol->vol_id = UBI_LAYOUT_VOLUME_ID;
0641 vol->ref_count = 1;
0642
0643 ubi_assert(!ubi->volumes[i]);
0644 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol;
0645 reserved_pebs += vol->reserved_pebs;
0646 ubi->vol_count += 1;
0647 vol->ubi = ubi;
0648 err = ubi_fastmap_init_checkmap(vol, UBI_LAYOUT_VOLUME_EBS);
0649 if (err)
0650 return err;
0651
0652 if (reserved_pebs > ubi->avail_pebs) {
0653 ubi_err(ubi, "not enough PEBs, required %d, available %d",
0654 reserved_pebs, ubi->avail_pebs);
0655 if (ubi->corr_peb_count)
0656 ubi_err(ubi, "%d PEBs are corrupted and not used",
0657 ubi->corr_peb_count);
0658 return -ENOSPC;
0659 }
0660 ubi->rsvd_pebs += reserved_pebs;
0661 ubi->avail_pebs -= reserved_pebs;
0662
0663 return 0;
0664 }
0665
0666
0667
0668
0669
0670
0671
0672
0673
0674 static int check_av(const struct ubi_volume *vol,
0675 const struct ubi_ainf_volume *av)
0676 {
0677 int err;
0678
0679 if (av->highest_lnum >= vol->reserved_pebs) {
0680 err = 1;
0681 goto bad;
0682 }
0683 if (av->leb_count > vol->reserved_pebs) {
0684 err = 2;
0685 goto bad;
0686 }
0687 if (av->vol_type != vol->vol_type) {
0688 err = 3;
0689 goto bad;
0690 }
0691 if (av->used_ebs > vol->reserved_pebs) {
0692 err = 4;
0693 goto bad;
0694 }
0695 if (av->data_pad != vol->data_pad) {
0696 err = 5;
0697 goto bad;
0698 }
0699 return 0;
0700
0701 bad:
0702 ubi_err(vol->ubi, "bad attaching information, error %d", err);
0703 ubi_dump_av(av);
0704 ubi_dump_vol_info(vol);
0705 return -EINVAL;
0706 }
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718 static int check_attaching_info(const struct ubi_device *ubi,
0719 struct ubi_attach_info *ai)
0720 {
0721 int err, i;
0722 struct ubi_ainf_volume *av;
0723 struct ubi_volume *vol;
0724
0725 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
0726 ubi_err(ubi, "found %d volumes while attaching, maximum is %d + %d",
0727 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
0728 return -EINVAL;
0729 }
0730
0731 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
0732 ai->highest_vol_id < UBI_INTERNAL_VOL_START) {
0733 ubi_err(ubi, "too large volume ID %d found",
0734 ai->highest_vol_id);
0735 return -EINVAL;
0736 }
0737
0738 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
0739 cond_resched();
0740
0741 av = ubi_find_av(ai, i);
0742 vol = ubi->volumes[i];
0743 if (!vol) {
0744 if (av)
0745 ubi_remove_av(ai, av);
0746 continue;
0747 }
0748
0749 if (vol->reserved_pebs == 0) {
0750 ubi_assert(i < ubi->vtbl_slots);
0751
0752 if (!av)
0753 continue;
0754
0755
0756
0757
0758
0759
0760
0761
0762 ubi_msg(ubi, "finish volume %d removal", av->vol_id);
0763 ubi_remove_av(ai, av);
0764 } else if (av) {
0765 err = check_av(vol, av);
0766 if (err)
0767 return err;
0768 }
0769 }
0770
0771 return 0;
0772 }
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783 int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
0784 {
0785 int err;
0786 struct ubi_ainf_volume *av;
0787
0788 empty_vtbl_record.crc = cpu_to_be32(0xf116c36b);
0789
0790
0791
0792
0793
0794 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
0795 if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
0796 ubi->vtbl_slots = UBI_MAX_VOLUMES;
0797
0798 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE;
0799 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size);
0800
0801 av = ubi_find_av(ai, UBI_LAYOUT_VOLUME_ID);
0802 if (!av) {
0803
0804
0805
0806
0807
0808
0809
0810
0811 if (ai->is_empty) {
0812 ubi->vtbl = create_empty_lvol(ubi, ai);
0813 if (IS_ERR(ubi->vtbl))
0814 return PTR_ERR(ubi->vtbl);
0815 } else {
0816 ubi_err(ubi, "the layout volume was not found");
0817 return -EINVAL;
0818 }
0819 } else {
0820 if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) {
0821
0822 ubi_err(ubi, "too many LEBs (%d) in layout volume",
0823 av->leb_count);
0824 return -EINVAL;
0825 }
0826
0827 ubi->vtbl = process_lvol(ubi, ai, av);
0828 if (IS_ERR(ubi->vtbl))
0829 return PTR_ERR(ubi->vtbl);
0830 }
0831
0832 ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count;
0833
0834
0835
0836
0837
0838 err = init_volumes(ubi, ai, ubi->vtbl);
0839 if (err)
0840 goto out_free;
0841
0842
0843
0844
0845
0846 err = check_attaching_info(ubi, ai);
0847 if (err)
0848 goto out_free;
0849
0850 return 0;
0851
0852 out_free:
0853 vfree(ubi->vtbl);
0854 ubi_free_all_volumes(ubi);
0855 return err;
0856 }
0857
0858
0859
0860
0861
0862 static void self_vtbl_check(const struct ubi_device *ubi)
0863 {
0864 if (!ubi_dbg_chk_gen(ubi))
0865 return;
0866
0867 if (vtbl_check(ubi, ubi->vtbl)) {
0868 ubi_err(ubi, "self-check failed");
0869 BUG();
0870 }
0871 }