aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/io.c')
-rw-r--r--drivers/mtd/ubi/io.c150
1 files changed, 77 insertions, 73 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index d36134925d31..396aaa543362 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -177,19 +177,20 @@ retry:
177 * enabled. A corresponding message will be printed 177 * enabled. A corresponding message will be printed
178 * later, when it is has been scrubbed. 178 * later, when it is has been scrubbed.
179 */ 179 */
180 ubi_msg("fixable bit-flip detected at PEB %d", pnum); 180 ubi_msg(ubi, "fixable bit-flip detected at PEB %d",
181 pnum);
181 ubi_assert(len == read); 182 ubi_assert(len == read);
182 return UBI_IO_BITFLIPS; 183 return UBI_IO_BITFLIPS;
183 } 184 }
184 185
185 if (retries++ < UBI_IO_RETRIES) { 186 if (retries++ < UBI_IO_RETRIES) {
186 ubi_warn("error %d%s while reading %d bytes from PEB %d:%d, read only %zd bytes, retry", 187 ubi_warn(ubi, "error %d%s while reading %d bytes from PEB %d:%d, read only %zd bytes, retry",
187 err, errstr, len, pnum, offset, read); 188 err, errstr, len, pnum, offset, read);
188 yield(); 189 yield();
189 goto retry; 190 goto retry;
190 } 191 }
191 192
192 ubi_err("error %d%s while reading %d bytes from PEB %d:%d, read %zd bytes", 193 ubi_err(ubi, "error %d%s while reading %d bytes from PEB %d:%d, read %zd bytes",
193 err, errstr, len, pnum, offset, read); 194 err, errstr, len, pnum, offset, read);
194 dump_stack(); 195 dump_stack();
195 196
@@ -246,7 +247,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
246 ubi_assert(len > 0 && len % ubi->hdrs_min_io_size == 0); 247 ubi_assert(len > 0 && len % ubi->hdrs_min_io_size == 0);
247 248
248 if (ubi->ro_mode) { 249 if (ubi->ro_mode) {
249 ubi_err("read-only mode"); 250 ubi_err(ubi, "read-only mode");
250 return -EROFS; 251 return -EROFS;
251 } 252 }
252 253
@@ -273,7 +274,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
273 } 274 }
274 275
275 if (ubi_dbg_is_write_failure(ubi)) { 276 if (ubi_dbg_is_write_failure(ubi)) {
276 ubi_err("cannot write %d bytes to PEB %d:%d (emulated)", 277 ubi_err(ubi, "cannot write %d bytes to PEB %d:%d (emulated)",
277 len, pnum, offset); 278 len, pnum, offset);
278 dump_stack(); 279 dump_stack();
279 return -EIO; 280 return -EIO;
@@ -282,7 +283,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
282 addr = (loff_t)pnum * ubi->peb_size + offset; 283 addr = (loff_t)pnum * ubi->peb_size + offset;
283 err = mtd_write(ubi->mtd, addr, len, &written, buf); 284 err = mtd_write(ubi->mtd, addr, len, &written, buf);
284 if (err) { 285 if (err) {
285 ubi_err("error %d while writing %d bytes to PEB %d:%d, written %zd bytes", 286 ubi_err(ubi, "error %d while writing %d bytes to PEB %d:%d, written %zd bytes",
286 err, len, pnum, offset, written); 287 err, len, pnum, offset, written);
287 dump_stack(); 288 dump_stack();
288 ubi_dump_flash(ubi, pnum, offset, len); 289 ubi_dump_flash(ubi, pnum, offset, len);
@@ -338,7 +339,7 @@ static int do_sync_erase(struct ubi_device *ubi, int pnum)
338 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 339 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
339 340
340 if (ubi->ro_mode) { 341 if (ubi->ro_mode) {
341 ubi_err("read-only mode"); 342 ubi_err(ubi, "read-only mode");
342 return -EROFS; 343 return -EROFS;
343 } 344 }
344 345
@@ -355,12 +356,12 @@ retry:
355 err = mtd_erase(ubi->mtd, &ei); 356 err = mtd_erase(ubi->mtd, &ei);
356 if (err) { 357 if (err) {
357 if (retries++ < UBI_IO_RETRIES) { 358 if (retries++ < UBI_IO_RETRIES) {
358 ubi_warn("error %d while erasing PEB %d, retry", 359 ubi_warn(ubi, "error %d while erasing PEB %d, retry",
359 err, pnum); 360 err, pnum);
360 yield(); 361 yield();
361 goto retry; 362 goto retry;
362 } 363 }
363 ubi_err("cannot erase PEB %d, error %d", pnum, err); 364 ubi_err(ubi, "cannot erase PEB %d, error %d", pnum, err);
364 dump_stack(); 365 dump_stack();
365 return err; 366 return err;
366 } 367 }
@@ -368,17 +369,18 @@ retry:
368 err = wait_event_interruptible(wq, ei.state == MTD_ERASE_DONE || 369 err = wait_event_interruptible(wq, ei.state == MTD_ERASE_DONE ||
369 ei.state == MTD_ERASE_FAILED); 370 ei.state == MTD_ERASE_FAILED);
370 if (err) { 371 if (err) {
371 ubi_err("interrupted PEB %d erasure", pnum); 372 ubi_err(ubi, "interrupted PEB %d erasure", pnum);
372 return -EINTR; 373 return -EINTR;
373 } 374 }
374 375
375 if (ei.state == MTD_ERASE_FAILED) { 376 if (ei.state == MTD_ERASE_FAILED) {
376 if (retries++ < UBI_IO_RETRIES) { 377 if (retries++ < UBI_IO_RETRIES) {
377 ubi_warn("error while erasing PEB %d, retry", pnum); 378 ubi_warn(ubi, "error while erasing PEB %d, retry",
379 pnum);
378 yield(); 380 yield();
379 goto retry; 381 goto retry;
380 } 382 }
381 ubi_err("cannot erase PEB %d", pnum); 383 ubi_err(ubi, "cannot erase PEB %d", pnum);
382 dump_stack(); 384 dump_stack();
383 return -EIO; 385 return -EIO;
384 } 386 }
@@ -388,7 +390,7 @@ retry:
388 return err; 390 return err;
389 391
390 if (ubi_dbg_is_erase_failure(ubi)) { 392 if (ubi_dbg_is_erase_failure(ubi)) {
391 ubi_err("cannot erase PEB %d (emulated)", pnum); 393 ubi_err(ubi, "cannot erase PEB %d (emulated)", pnum);
392 return -EIO; 394 return -EIO;
393 } 395 }
394 396
@@ -411,7 +413,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
411{ 413{
412 int err, i, patt_count; 414 int err, i, patt_count;
413 415
414 ubi_msg("run torture test for PEB %d", pnum); 416 ubi_msg(ubi, "run torture test for PEB %d", pnum);
415 patt_count = ARRAY_SIZE(patterns); 417 patt_count = ARRAY_SIZE(patterns);
416 ubi_assert(patt_count > 0); 418 ubi_assert(patt_count > 0);
417 419
@@ -428,7 +430,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
428 430
429 err = ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->peb_size); 431 err = ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->peb_size);
430 if (err == 0) { 432 if (err == 0) {
431 ubi_err("erased PEB %d, but a non-0xFF byte found", 433 ubi_err(ubi, "erased PEB %d, but a non-0xFF byte found",
432 pnum); 434 pnum);
433 err = -EIO; 435 err = -EIO;
434 goto out; 436 goto out;
@@ -448,7 +450,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
448 err = ubi_check_pattern(ubi->peb_buf, patterns[i], 450 err = ubi_check_pattern(ubi->peb_buf, patterns[i],
449 ubi->peb_size); 451 ubi->peb_size);
450 if (err == 0) { 452 if (err == 0) {
451 ubi_err("pattern %x checking failed for PEB %d", 453 ubi_err(ubi, "pattern %x checking failed for PEB %d",
452 patterns[i], pnum); 454 patterns[i], pnum);
453 err = -EIO; 455 err = -EIO;
454 goto out; 456 goto out;
@@ -456,7 +458,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
456 } 458 }
457 459
458 err = patt_count; 460 err = patt_count;
459 ubi_msg("PEB %d passed torture test, do not mark it as bad", pnum); 461 ubi_msg(ubi, "PEB %d passed torture test, do not mark it as bad", pnum);
460 462
461out: 463out:
462 mutex_unlock(&ubi->buf_mutex); 464 mutex_unlock(&ubi->buf_mutex);
@@ -466,7 +468,7 @@ out:
466 * has not passed because it happened on a freshly erased 468 * has not passed because it happened on a freshly erased
467 * physical eraseblock which means something is wrong with it. 469 * physical eraseblock which means something is wrong with it.
468 */ 470 */
469 ubi_err("read problems on freshly erased PEB %d, must be bad", 471 ubi_err(ubi, "read problems on freshly erased PEB %d, must be bad",
470 pnum); 472 pnum);
471 err = -EIO; 473 err = -EIO;
472 } 474 }
@@ -542,7 +544,7 @@ error:
542 * it. Supposedly the flash media or the driver is screwed up, so 544 * it. Supposedly the flash media or the driver is screwed up, so
543 * return an error. 545 * return an error.
544 */ 546 */
545 ubi_err("cannot invalidate PEB %d, write returned %d", pnum, err); 547 ubi_err(ubi, "cannot invalidate PEB %d, write returned %d", pnum, err);
546 ubi_dump_flash(ubi, pnum, 0, ubi->peb_size); 548 ubi_dump_flash(ubi, pnum, 0, ubi->peb_size);
547 return -EIO; 549 return -EIO;
548} 550}
@@ -574,7 +576,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
574 return err; 576 return err;
575 577
576 if (ubi->ro_mode) { 578 if (ubi->ro_mode) {
577 ubi_err("read-only mode"); 579 ubi_err(ubi, "read-only mode");
578 return -EROFS; 580 return -EROFS;
579 } 581 }
580 582
@@ -616,7 +618,7 @@ int ubi_io_is_bad(const struct ubi_device *ubi, int pnum)
616 618
617 ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size); 619 ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size);
618 if (ret < 0) 620 if (ret < 0)
619 ubi_err("error %d while checking if PEB %d is bad", 621 ubi_err(ubi, "error %d while checking if PEB %d is bad",
620 ret, pnum); 622 ret, pnum);
621 else if (ret) 623 else if (ret)
622 dbg_io("PEB %d is bad", pnum); 624 dbg_io("PEB %d is bad", pnum);
@@ -642,7 +644,7 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
642 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 644 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
643 645
644 if (ubi->ro_mode) { 646 if (ubi->ro_mode) {
645 ubi_err("read-only mode"); 647 ubi_err(ubi, "read-only mode");
646 return -EROFS; 648 return -EROFS;
647 } 649 }
648 650
@@ -651,7 +653,7 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
651 653
652 err = mtd_block_markbad(mtd, (loff_t)pnum * ubi->peb_size); 654 err = mtd_block_markbad(mtd, (loff_t)pnum * ubi->peb_size);
653 if (err) 655 if (err)
654 ubi_err("cannot mark PEB %d bad, error %d", pnum, err); 656 ubi_err(ubi, "cannot mark PEB %d bad, error %d", pnum, err);
655 return err; 657 return err;
656} 658}
657 659
@@ -674,32 +676,32 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
674 leb_start = be32_to_cpu(ec_hdr->data_offset); 676 leb_start = be32_to_cpu(ec_hdr->data_offset);
675 677
676 if (ec_hdr->version != UBI_VERSION) { 678 if (ec_hdr->version != UBI_VERSION) {
677 ubi_err("node with incompatible UBI version found: this UBI version is %d, image version is %d", 679 ubi_err(ubi, "node with incompatible UBI version found: this UBI version is %d, image version is %d",
678 UBI_VERSION, (int)ec_hdr->version); 680 UBI_VERSION, (int)ec_hdr->version);
679 goto bad; 681 goto bad;
680 } 682 }
681 683
682 if (vid_hdr_offset != ubi->vid_hdr_offset) { 684 if (vid_hdr_offset != ubi->vid_hdr_offset) {
683 ubi_err("bad VID header offset %d, expected %d", 685 ubi_err(ubi, "bad VID header offset %d, expected %d",
684 vid_hdr_offset, ubi->vid_hdr_offset); 686 vid_hdr_offset, ubi->vid_hdr_offset);
685 goto bad; 687 goto bad;
686 } 688 }
687 689
688 if (leb_start != ubi->leb_start) { 690 if (leb_start != ubi->leb_start) {
689 ubi_err("bad data offset %d, expected %d", 691 ubi_err(ubi, "bad data offset %d, expected %d",
690 leb_start, ubi->leb_start); 692 leb_start, ubi->leb_start);
691 goto bad; 693 goto bad;
692 } 694 }
693 695
694 if (ec < 0 || ec > UBI_MAX_ERASECOUNTER) { 696 if (ec < 0 || ec > UBI_MAX_ERASECOUNTER) {
695 ubi_err("bad erase counter %lld", ec); 697 ubi_err(ubi, "bad erase counter %lld", ec);
696 goto bad; 698 goto bad;
697 } 699 }
698 700
699 return 0; 701 return 0;
700 702
701bad: 703bad:
702 ubi_err("bad EC header"); 704 ubi_err(ubi, "bad EC header");
703 ubi_dump_ec_hdr(ec_hdr); 705 ubi_dump_ec_hdr(ec_hdr);
704 dump_stack(); 706 dump_stack();
705 return 1; 707 return 1;
@@ -765,7 +767,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
765 if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { 767 if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
766 /* The physical eraseblock is supposedly empty */ 768 /* The physical eraseblock is supposedly empty */
767 if (verbose) 769 if (verbose)
768 ubi_warn("no EC header found at PEB %d, only 0xFF bytes", 770 ubi_warn(ubi, "no EC header found at PEB %d, only 0xFF bytes",
769 pnum); 771 pnum);
770 dbg_bld("no EC header found at PEB %d, only 0xFF bytes", 772 dbg_bld("no EC header found at PEB %d, only 0xFF bytes",
771 pnum); 773 pnum);
@@ -780,7 +782,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
780 * 0xFF bytes. Report that the header is corrupted. 782 * 0xFF bytes. Report that the header is corrupted.
781 */ 783 */
782 if (verbose) { 784 if (verbose) {
783 ubi_warn("bad magic number at PEB %d: %08x instead of %08x", 785 ubi_warn(ubi, "bad magic number at PEB %d: %08x instead of %08x",
784 pnum, magic, UBI_EC_HDR_MAGIC); 786 pnum, magic, UBI_EC_HDR_MAGIC);
785 ubi_dump_ec_hdr(ec_hdr); 787 ubi_dump_ec_hdr(ec_hdr);
786 } 788 }
@@ -794,7 +796,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
794 796
795 if (hdr_crc != crc) { 797 if (hdr_crc != crc) {
796 if (verbose) { 798 if (verbose) {
797 ubi_warn("bad EC header CRC at PEB %d, calculated %#08x, read %#08x", 799 ubi_warn(ubi, "bad EC header CRC at PEB %d, calculated %#08x, read %#08x",
798 pnum, crc, hdr_crc); 800 pnum, crc, hdr_crc);
799 ubi_dump_ec_hdr(ec_hdr); 801 ubi_dump_ec_hdr(ec_hdr);
800 } 802 }
@@ -810,7 +812,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
810 /* And of course validate what has just been read from the media */ 812 /* And of course validate what has just been read from the media */
811 err = validate_ec_hdr(ubi, ec_hdr); 813 err = validate_ec_hdr(ubi, ec_hdr);
812 if (err) { 814 if (err) {
813 ubi_err("validation failed for PEB %d", pnum); 815 ubi_err(ubi, "validation failed for PEB %d", pnum);
814 return -EINVAL; 816 return -EINVAL;
815 } 817 }
816 818
@@ -884,40 +886,40 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
884 int usable_leb_size = ubi->leb_size - data_pad; 886 int usable_leb_size = ubi->leb_size - data_pad;
885 887
886 if (copy_flag != 0 && copy_flag != 1) { 888 if (copy_flag != 0 && copy_flag != 1) {
887 ubi_err("bad copy_flag"); 889 ubi_err(ubi, "bad copy_flag");
888 goto bad; 890 goto bad;
889 } 891 }
890 892
891 if (vol_id < 0 || lnum < 0 || data_size < 0 || used_ebs < 0 || 893 if (vol_id < 0 || lnum < 0 || data_size < 0 || used_ebs < 0 ||
892 data_pad < 0) { 894 data_pad < 0) {
893 ubi_err("negative values"); 895 ubi_err(ubi, "negative values");
894 goto bad; 896 goto bad;
895 } 897 }
896 898
897 if (vol_id >= UBI_MAX_VOLUMES && vol_id < UBI_INTERNAL_VOL_START) { 899 if (vol_id >= UBI_MAX_VOLUMES && vol_id < UBI_INTERNAL_VOL_START) {
898 ubi_err("bad vol_id"); 900 ubi_err(ubi, "bad vol_id");
899 goto bad; 901 goto bad;
900 } 902 }
901 903
902 if (vol_id < UBI_INTERNAL_VOL_START && compat != 0) { 904 if (vol_id < UBI_INTERNAL_VOL_START && compat != 0) {
903 ubi_err("bad compat"); 905 ubi_err(ubi, "bad compat");
904 goto bad; 906 goto bad;
905 } 907 }
906 908
907 if (vol_id >= UBI_INTERNAL_VOL_START && compat != UBI_COMPAT_DELETE && 909 if (vol_id >= UBI_INTERNAL_VOL_START && compat != UBI_COMPAT_DELETE &&
908 compat != UBI_COMPAT_RO && compat != UBI_COMPAT_PRESERVE && 910 compat != UBI_COMPAT_RO && compat != UBI_COMPAT_PRESERVE &&
909 compat != UBI_COMPAT_REJECT) { 911 compat != UBI_COMPAT_REJECT) {
910 ubi_err("bad compat"); 912 ubi_err(ubi, "bad compat");
911 goto bad; 913 goto bad;
912 } 914 }
913 915
914 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { 916 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) {
915 ubi_err("bad vol_type"); 917 ubi_err(ubi, "bad vol_type");
916 goto bad; 918 goto bad;
917 } 919 }
918 920
919 if (data_pad >= ubi->leb_size / 2) { 921 if (data_pad >= ubi->leb_size / 2) {
920 ubi_err("bad data_pad"); 922 ubi_err(ubi, "bad data_pad");
921 goto bad; 923 goto bad;
922 } 924 }
923 925
@@ -929,45 +931,45 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
929 * mapped logical eraseblocks. 931 * mapped logical eraseblocks.
930 */ 932 */
931 if (used_ebs == 0) { 933 if (used_ebs == 0) {
932 ubi_err("zero used_ebs"); 934 ubi_err(ubi, "zero used_ebs");
933 goto bad; 935 goto bad;
934 } 936 }
935 if (data_size == 0) { 937 if (data_size == 0) {
936 ubi_err("zero data_size"); 938 ubi_err(ubi, "zero data_size");
937 goto bad; 939 goto bad;
938 } 940 }
939 if (lnum < used_ebs - 1) { 941 if (lnum < used_ebs - 1) {
940 if (data_size != usable_leb_size) { 942 if (data_size != usable_leb_size) {
941 ubi_err("bad data_size"); 943 ubi_err(ubi, "bad data_size");
942 goto bad; 944 goto bad;
943 } 945 }
944 } else if (lnum == used_ebs - 1) { 946 } else if (lnum == used_ebs - 1) {
945 if (data_size == 0) { 947 if (data_size == 0) {
946 ubi_err("bad data_size at last LEB"); 948 ubi_err(ubi, "bad data_size at last LEB");
947 goto bad; 949 goto bad;
948 } 950 }
949 } else { 951 } else {
950 ubi_err("too high lnum"); 952 ubi_err(ubi, "too high lnum");
951 goto bad; 953 goto bad;
952 } 954 }
953 } else { 955 } else {
954 if (copy_flag == 0) { 956 if (copy_flag == 0) {
955 if (data_crc != 0) { 957 if (data_crc != 0) {
956 ubi_err("non-zero data CRC"); 958 ubi_err(ubi, "non-zero data CRC");
957 goto bad; 959 goto bad;
958 } 960 }
959 if (data_size != 0) { 961 if (data_size != 0) {
960 ubi_err("non-zero data_size"); 962 ubi_err(ubi, "non-zero data_size");
961 goto bad; 963 goto bad;
962 } 964 }
963 } else { 965 } else {
964 if (data_size == 0) { 966 if (data_size == 0) {
965 ubi_err("zero data_size of copy"); 967 ubi_err(ubi, "zero data_size of copy");
966 goto bad; 968 goto bad;
967 } 969 }
968 } 970 }
969 if (used_ebs != 0) { 971 if (used_ebs != 0) {
970 ubi_err("bad used_ebs"); 972 ubi_err(ubi, "bad used_ebs");
971 goto bad; 973 goto bad;
972 } 974 }
973 } 975 }
@@ -975,7 +977,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
975 return 0; 977 return 0;
976 978
977bad: 979bad:
978 ubi_err("bad VID header"); 980 ubi_err(ubi, "bad VID header");
979 ubi_dump_vid_hdr(vid_hdr); 981 ubi_dump_vid_hdr(vid_hdr);
980 dump_stack(); 982 dump_stack();
981 return 1; 983 return 1;
@@ -1020,7 +1022,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1020 1022
1021 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 1023 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
1022 if (verbose) 1024 if (verbose)
1023 ubi_warn("no VID header found at PEB %d, only 0xFF bytes", 1025 ubi_warn(ubi, "no VID header found at PEB %d, only 0xFF bytes",
1024 pnum); 1026 pnum);
1025 dbg_bld("no VID header found at PEB %d, only 0xFF bytes", 1027 dbg_bld("no VID header found at PEB %d, only 0xFF bytes",
1026 pnum); 1028 pnum);
@@ -1031,7 +1033,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1031 } 1033 }
1032 1034
1033 if (verbose) { 1035 if (verbose) {
1034 ubi_warn("bad magic number at PEB %d: %08x instead of %08x", 1036 ubi_warn(ubi, "bad magic number at PEB %d: %08x instead of %08x",
1035 pnum, magic, UBI_VID_HDR_MAGIC); 1037 pnum, magic, UBI_VID_HDR_MAGIC);
1036 ubi_dump_vid_hdr(vid_hdr); 1038 ubi_dump_vid_hdr(vid_hdr);
1037 } 1039 }
@@ -1045,7 +1047,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1045 1047
1046 if (hdr_crc != crc) { 1048 if (hdr_crc != crc) {
1047 if (verbose) { 1049 if (verbose) {
1048 ubi_warn("bad CRC at PEB %d, calculated %#08x, read %#08x", 1050 ubi_warn(ubi, "bad CRC at PEB %d, calculated %#08x, read %#08x",
1049 pnum, crc, hdr_crc); 1051 pnum, crc, hdr_crc);
1050 ubi_dump_vid_hdr(vid_hdr); 1052 ubi_dump_vid_hdr(vid_hdr);
1051 } 1053 }
@@ -1059,7 +1061,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1059 1061
1060 err = validate_vid_hdr(ubi, vid_hdr); 1062 err = validate_vid_hdr(ubi, vid_hdr);
1061 if (err) { 1063 if (err) {
1062 ubi_err("validation failed for PEB %d", pnum); 1064 ubi_err(ubi, "validation failed for PEB %d", pnum);
1063 return -EINVAL; 1065 return -EINVAL;
1064 } 1066 }
1065 1067
@@ -1129,7 +1131,7 @@ static int self_check_not_bad(const struct ubi_device *ubi, int pnum)
1129 if (!err) 1131 if (!err)
1130 return err; 1132 return err;
1131 1133
1132 ubi_err("self-check failed for PEB %d", pnum); 1134 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1133 dump_stack(); 1135 dump_stack();
1134 return err > 0 ? -EINVAL : err; 1136 return err > 0 ? -EINVAL : err;
1135} 1137}
@@ -1154,14 +1156,14 @@ static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1154 1156
1155 magic = be32_to_cpu(ec_hdr->magic); 1157 magic = be32_to_cpu(ec_hdr->magic);
1156 if (magic != UBI_EC_HDR_MAGIC) { 1158 if (magic != UBI_EC_HDR_MAGIC) {
1157 ubi_err("bad magic %#08x, must be %#08x", 1159 ubi_err(ubi, "bad magic %#08x, must be %#08x",
1158 magic, UBI_EC_HDR_MAGIC); 1160 magic, UBI_EC_HDR_MAGIC);
1159 goto fail; 1161 goto fail;
1160 } 1162 }
1161 1163
1162 err = validate_ec_hdr(ubi, ec_hdr); 1164 err = validate_ec_hdr(ubi, ec_hdr);
1163 if (err) { 1165 if (err) {
1164 ubi_err("self-check failed for PEB %d", pnum); 1166 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1165 goto fail; 1167 goto fail;
1166 } 1168 }
1167 1169
@@ -1201,8 +1203,9 @@ static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1201 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 1203 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
1202 hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); 1204 hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);
1203 if (hdr_crc != crc) { 1205 if (hdr_crc != crc) {
1204 ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); 1206 ubi_err(ubi, "bad CRC, calculated %#08x, read %#08x",
1205 ubi_err("self-check failed for PEB %d", pnum); 1207 crc, hdr_crc);
1208 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1206 ubi_dump_ec_hdr(ec_hdr); 1209 ubi_dump_ec_hdr(ec_hdr);
1207 dump_stack(); 1210 dump_stack();
1208 err = -EINVAL; 1211 err = -EINVAL;
@@ -1236,21 +1239,21 @@ static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum,
1236 1239
1237 magic = be32_to_cpu(vid_hdr->magic); 1240 magic = be32_to_cpu(vid_hdr->magic);
1238 if (magic != UBI_VID_HDR_MAGIC) { 1241 if (magic != UBI_VID_HDR_MAGIC) {
1239 ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x", 1242 ubi_err(ubi, "bad VID header magic %#08x at PEB %d, must be %#08x",
1240 magic, pnum, UBI_VID_HDR_MAGIC); 1243 magic, pnum, UBI_VID_HDR_MAGIC);
1241 goto fail; 1244 goto fail;
1242 } 1245 }
1243 1246
1244 err = validate_vid_hdr(ubi, vid_hdr); 1247 err = validate_vid_hdr(ubi, vid_hdr);
1245 if (err) { 1248 if (err) {
1246 ubi_err("self-check failed for PEB %d", pnum); 1249 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1247 goto fail; 1250 goto fail;
1248 } 1251 }
1249 1252
1250 return err; 1253 return err;
1251 1254
1252fail: 1255fail:
1253 ubi_err("self-check failed for PEB %d", pnum); 1256 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1254 ubi_dump_vid_hdr(vid_hdr); 1257 ubi_dump_vid_hdr(vid_hdr);
1255 dump_stack(); 1258 dump_stack();
1256 return -EINVAL; 1259 return -EINVAL;
@@ -1288,9 +1291,9 @@ static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1288 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); 1291 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
1289 hdr_crc = be32_to_cpu(vid_hdr->hdr_crc); 1292 hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
1290 if (hdr_crc != crc) { 1293 if (hdr_crc != crc) {
1291 ubi_err("bad VID header CRC at PEB %d, calculated %#08x, read %#08x", 1294 ubi_err(ubi, "bad VID header CRC at PEB %d, calculated %#08x, read %#08x",
1292 pnum, crc, hdr_crc); 1295 pnum, crc, hdr_crc);
1293 ubi_err("self-check failed for PEB %d", pnum); 1296 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1294 ubi_dump_vid_hdr(vid_hdr); 1297 ubi_dump_vid_hdr(vid_hdr);
1295 dump_stack(); 1298 dump_stack();
1296 err = -EINVAL; 1299 err = -EINVAL;
@@ -1329,7 +1332,7 @@ static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1329 1332
1330 buf1 = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); 1333 buf1 = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
1331 if (!buf1) { 1334 if (!buf1) {
1332 ubi_err("cannot allocate memory to check writes"); 1335 ubi_err(ubi, "cannot allocate memory to check writes");
1333 return 0; 1336 return 0;
1334 } 1337 }
1335 1338
@@ -1345,15 +1348,15 @@ static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1345 if (c == c1) 1348 if (c == c1)
1346 continue; 1349 continue;
1347 1350
1348 ubi_err("self-check failed for PEB %d:%d, len %d", 1351 ubi_err(ubi, "self-check failed for PEB %d:%d, len %d",
1349 pnum, offset, len); 1352 pnum, offset, len);
1350 ubi_msg("data differ at position %d", i); 1353 ubi_msg(ubi, "data differ at position %d", i);
1351 dump_len = max_t(int, 128, len - i); 1354 dump_len = max_t(int, 128, len - i);
1352 ubi_msg("hex dump of the original buffer from %d to %d", 1355 ubi_msg(ubi, "hex dump of the original buffer from %d to %d",
1353 i, i + dump_len); 1356 i, i + dump_len);
1354 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1357 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1355 buf + i, dump_len, 1); 1358 buf + i, dump_len, 1);
1356 ubi_msg("hex dump of the read buffer from %d to %d", 1359 ubi_msg(ubi, "hex dump of the read buffer from %d to %d",
1357 i, i + dump_len); 1360 i, i + dump_len);
1358 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1361 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1359 buf1 + i, dump_len, 1); 1362 buf1 + i, dump_len, 1);
@@ -1393,20 +1396,20 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1393 1396
1394 buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); 1397 buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
1395 if (!buf) { 1398 if (!buf) {
1396 ubi_err("cannot allocate memory to check for 0xFFs"); 1399 ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
1397 return 0; 1400 return 0;
1398 } 1401 }
1399 1402
1400 err = mtd_read(ubi->mtd, addr, len, &read, buf); 1403 err = mtd_read(ubi->mtd, addr, len, &read, buf);
1401 if (err && !mtd_is_bitflip(err)) { 1404 if (err && !mtd_is_bitflip(err)) {
1402 ubi_err("error %d while reading %d bytes from PEB %d:%d, read %zd bytes", 1405 ubi_err(ubi, "err %d while reading %d bytes from PEB %d:%d, read %zd bytes",
1403 err, len, pnum, offset, read); 1406 err, len, pnum, offset, read);
1404 goto error; 1407 goto error;
1405 } 1408 }
1406 1409
1407 err = ubi_check_pattern(buf, 0xFF, len); 1410 err = ubi_check_pattern(buf, 0xFF, len);
1408 if (err == 0) { 1411 if (err == 0) {
1409 ubi_err("flash region at PEB %d:%d, length %d does not contain all 0xFF bytes", 1412 ubi_err(ubi, "flash region at PEB %d:%d, length %d does not contain all 0xFF bytes",
1410 pnum, offset, len); 1413 pnum, offset, len);
1411 goto fail; 1414 goto fail;
1412 } 1415 }
@@ -1415,8 +1418,9 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1415 return 0; 1418 return 0;
1416 1419
1417fail: 1420fail:
1418 ubi_err("self-check failed for PEB %d", pnum); 1421 ubi_err(ubi, "self-check failed for PEB %d", pnum);
1419 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1422 ubi_msg(ubi, "hex dump of the %d-%d region",
1423 offset, offset + len);
1420 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); 1424 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
1421 err = -EINVAL; 1425 err = -EINVAL;
1422error: 1426error: