aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-12 12:57:22 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-12 12:57:22 -0500
commitccb5a4910d0ca7b1742b9217db2e1b95817e25ac (patch)
tree721ea6e0e06376366f7cfcb358eb61b8a9dc9c65
parentc05e14f7b3145ac89635fa398934438240dace40 (diff)
parentf38aed975c0c3645bbdfc5ebe35726e64caaf588 (diff)
Merge tag 'upstream-3.19-rc1' of git://git.infradead.org/linux-ubifs
Pull UBI/UBIFS updates from Artem Bityutskiy: "This includes the following UBI/UBIFS changes: - UBI debug messages now include the UBI device number. This change is responsible for the big diffstat since it touched every debugging print statement. - An Xattr bug-fix which fixes SELinux support - Several error path fixes in UBI/UBIFS" * tag 'upstream-3.19-rc1' of git://git.infradead.org/linux-ubifs: UBI: Fix invalid vfree() UBI: Fix double free after do_sync_erase() UBIFS: fix a couple bugs in UBIFS xattr length calculation UBI: vtbl: Use ubi_eba_atomic_leb_change() UBI: Extend UBI layer debug/messaging capabilities UBIFS: fix budget leak in error path
-rw-r--r--drivers/mtd/ubi/attach.c126
-rw-r--r--drivers/mtd/ubi/block.c41
-rw-r--r--drivers/mtd/ubi/build.c126
-rw-r--r--drivers/mtd/ubi/cdev.c36
-rw-r--r--drivers/mtd/ubi/debug.c10
-rw-r--r--drivers/mtd/ubi/eba.c53
-rw-r--r--drivers/mtd/ubi/fastmap.c96
-rw-r--r--drivers/mtd/ubi/io.c150
-rw-r--r--drivers/mtd/ubi/kapi.c6
-rw-r--r--drivers/mtd/ubi/misc.c4
-rw-r--r--drivers/mtd/ubi/ubi.h13
-rw-r--r--drivers/mtd/ubi/upd.c10
-rw-r--r--drivers/mtd/ubi/vmt.c69
-rw-r--r--drivers/mtd/ubi/vtbl.c71
-rw-r--r--drivers/mtd/ubi/wl.c80
-rw-r--r--fs/ubifs/file.c1
-rw-r--r--fs/ubifs/journal.c7
17 files changed, 466 insertions, 433 deletions
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 6f27d9a1be3b..9d2e16f3150a 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -176,6 +176,7 @@ static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec)
176 176
177/** 177/**
178 * validate_vid_hdr - check volume identifier header. 178 * validate_vid_hdr - check volume identifier header.
179 * @ubi: UBI device description object
179 * @vid_hdr: the volume identifier header to check 180 * @vid_hdr: the volume identifier header to check
180 * @av: information about the volume this logical eraseblock belongs to 181 * @av: information about the volume this logical eraseblock belongs to
181 * @pnum: physical eraseblock number the VID header came from 182 * @pnum: physical eraseblock number the VID header came from
@@ -188,7 +189,8 @@ static int add_corrupted(struct ubi_attach_info *ai, int pnum, int ec)
188 * information in the VID header is consistent to the information in other VID 189 * information in the VID header is consistent to the information in other VID
189 * headers of the same volume. 190 * headers of the same volume.
190 */ 191 */
191static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr, 192static int validate_vid_hdr(const struct ubi_device *ubi,
193 const struct ubi_vid_hdr *vid_hdr,
192 const struct ubi_ainf_volume *av, int pnum) 194 const struct ubi_ainf_volume *av, int pnum)
193{ 195{
194 int vol_type = vid_hdr->vol_type; 196 int vol_type = vid_hdr->vol_type;
@@ -206,7 +208,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
206 */ 208 */
207 209
208 if (vol_id != av->vol_id) { 210 if (vol_id != av->vol_id) {
209 ubi_err("inconsistent vol_id"); 211 ubi_err(ubi, "inconsistent vol_id");
210 goto bad; 212 goto bad;
211 } 213 }
212 214
@@ -216,17 +218,17 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
216 av_vol_type = UBI_VID_DYNAMIC; 218 av_vol_type = UBI_VID_DYNAMIC;
217 219
218 if (vol_type != av_vol_type) { 220 if (vol_type != av_vol_type) {
219 ubi_err("inconsistent vol_type"); 221 ubi_err(ubi, "inconsistent vol_type");
220 goto bad; 222 goto bad;
221 } 223 }
222 224
223 if (used_ebs != av->used_ebs) { 225 if (used_ebs != av->used_ebs) {
224 ubi_err("inconsistent used_ebs"); 226 ubi_err(ubi, "inconsistent used_ebs");
225 goto bad; 227 goto bad;
226 } 228 }
227 229
228 if (data_pad != av->data_pad) { 230 if (data_pad != av->data_pad) {
229 ubi_err("inconsistent data_pad"); 231 ubi_err(ubi, "inconsistent data_pad");
230 goto bad; 232 goto bad;
231 } 233 }
232 } 234 }
@@ -234,7 +236,7 @@ static int validate_vid_hdr(const struct ubi_vid_hdr *vid_hdr,
234 return 0; 236 return 0;
235 237
236bad: 238bad:
237 ubi_err("inconsistent VID header at PEB %d", pnum); 239 ubi_err(ubi, "inconsistent VID header at PEB %d", pnum);
238 ubi_dump_vid_hdr(vid_hdr); 240 ubi_dump_vid_hdr(vid_hdr);
239 ubi_dump_av(av); 241 ubi_dump_av(av);
240 return -EINVAL; 242 return -EINVAL;
@@ -336,7 +338,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
336 * support these images anymore. Well, those images still work, 338 * support these images anymore. Well, those images still work,
337 * but only if no unclean reboots happened. 339 * but only if no unclean reboots happened.
338 */ 340 */
339 ubi_err("unsupported on-flash UBI format"); 341 ubi_err(ubi, "unsupported on-flash UBI format");
340 return -EINVAL; 342 return -EINVAL;
341 } 343 }
342 344
@@ -377,7 +379,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
377 if (err == UBI_IO_BITFLIPS) 379 if (err == UBI_IO_BITFLIPS)
378 bitflips = 1; 380 bitflips = 1;
379 else { 381 else {
380 ubi_err("VID of PEB %d header is bad, but it was OK earlier, err %d", 382 ubi_err(ubi, "VID of PEB %d header is bad, but it was OK earlier, err %d",
381 pnum, err); 383 pnum, err);
382 if (err > 0) 384 if (err > 0)
383 err = -EIO; 385 err = -EIO;
@@ -507,7 +509,7 @@ int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
507 * logical eraseblocks because there was an unclean reboot. 509 * logical eraseblocks because there was an unclean reboot.
508 */ 510 */
509 if (aeb->sqnum == sqnum && sqnum != 0) { 511 if (aeb->sqnum == sqnum && sqnum != 0) {
510 ubi_err("two LEBs with same sequence number %llu", 512 ubi_err(ubi, "two LEBs with same sequence number %llu",
511 sqnum); 513 sqnum);
512 ubi_dump_aeb(aeb, 0); 514 ubi_dump_aeb(aeb, 0);
513 ubi_dump_vid_hdr(vid_hdr); 515 ubi_dump_vid_hdr(vid_hdr);
@@ -527,7 +529,7 @@ int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
527 * This logical eraseblock is newer than the one 529 * This logical eraseblock is newer than the one
528 * found earlier. 530 * found earlier.
529 */ 531 */
530 err = validate_vid_hdr(vid_hdr, av, pnum); 532 err = validate_vid_hdr(ubi, vid_hdr, av, pnum);
531 if (err) 533 if (err)
532 return err; 534 return err;
533 535
@@ -565,7 +567,7 @@ int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
565 * attaching information. 567 * attaching information.
566 */ 568 */
567 569
568 err = validate_vid_hdr(vid_hdr, av, pnum); 570 err = validate_vid_hdr(ubi, vid_hdr, av, pnum);
569 if (err) 571 if (err)
570 return err; 572 return err;
571 573
@@ -668,7 +670,8 @@ static int early_erase_peb(struct ubi_device *ubi,
668 * Erase counter overflow. Upgrade UBI and use 64-bit 670 * Erase counter overflow. Upgrade UBI and use 64-bit
669 * erase counters internally. 671 * erase counters internally.
670 */ 672 */
671 ubi_err("erase counter overflow at PEB %d, EC %d", pnum, ec); 673 ubi_err(ubi, "erase counter overflow at PEB %d, EC %d",
674 pnum, ec);
672 return -EINVAL; 675 return -EINVAL;
673 } 676 }
674 677
@@ -736,7 +739,7 @@ struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
736 return aeb; 739 return aeb;
737 } 740 }
738 741
739 ubi_err("no free eraseblocks"); 742 ubi_err(ubi, "no free eraseblocks");
740 return ERR_PTR(-ENOSPC); 743 return ERR_PTR(-ENOSPC);
741} 744}
742 745
@@ -785,9 +788,9 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
785 if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size)) 788 if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size))
786 goto out_unlock; 789 goto out_unlock;
787 790
788 ubi_err("PEB %d contains corrupted VID header, and the data does not contain all 0xFF", 791 ubi_err(ubi, "PEB %d contains corrupted VID header, and the data does not contain all 0xFF",
789 pnum); 792 pnum);
790 ubi_err("this may be a non-UBI PEB or a severe VID header corruption which requires manual inspection"); 793 ubi_err(ubi, "this may be a non-UBI PEB or a severe VID header corruption which requires manual inspection");
791 ubi_dump_vid_hdr(vid_hdr); 794 ubi_dump_vid_hdr(vid_hdr);
792 pr_err("hexdump of PEB %d offset %d, length %d", 795 pr_err("hexdump of PEB %d offset %d, length %d",
793 pnum, ubi->leb_start, ubi->leb_size); 796 pnum, ubi->leb_start, ubi->leb_size);
@@ -859,7 +862,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
859 bitflips = 1; 862 bitflips = 1;
860 break; 863 break;
861 default: 864 default:
862 ubi_err("'ubi_io_read_ec_hdr()' returned unknown code %d", err); 865 ubi_err(ubi, "'ubi_io_read_ec_hdr()' returned unknown code %d",
866 err);
863 return -EINVAL; 867 return -EINVAL;
864 } 868 }
865 869
@@ -868,7 +872,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
868 872
869 /* Make sure UBI version is OK */ 873 /* Make sure UBI version is OK */
870 if (ech->version != UBI_VERSION) { 874 if (ech->version != UBI_VERSION) {
871 ubi_err("this UBI version is %d, image version is %d", 875 ubi_err(ubi, "this UBI version is %d, image version is %d",
872 UBI_VERSION, (int)ech->version); 876 UBI_VERSION, (int)ech->version);
873 return -EINVAL; 877 return -EINVAL;
874 } 878 }
@@ -882,7 +886,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
882 * flash. Upgrade UBI and use 64-bit erase counters 886 * flash. Upgrade UBI and use 64-bit erase counters
883 * internally. 887 * internally.
884 */ 888 */
885 ubi_err("erase counter overflow, max is %d", 889 ubi_err(ubi, "erase counter overflow, max is %d",
886 UBI_MAX_ERASECOUNTER); 890 UBI_MAX_ERASECOUNTER);
887 ubi_dump_ec_hdr(ech); 891 ubi_dump_ec_hdr(ech);
888 return -EINVAL; 892 return -EINVAL;
@@ -903,7 +907,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
903 if (!ubi->image_seq) 907 if (!ubi->image_seq)
904 ubi->image_seq = image_seq; 908 ubi->image_seq = image_seq;
905 if (image_seq && ubi->image_seq != image_seq) { 909 if (image_seq && ubi->image_seq != image_seq) {
906 ubi_err("bad image sequence number %d in PEB %d, expected %d", 910 ubi_err(ubi, "bad image sequence number %d in PEB %d, expected %d",
907 image_seq, pnum, ubi->image_seq); 911 image_seq, pnum, ubi->image_seq);
908 ubi_dump_ec_hdr(ech); 912 ubi_dump_ec_hdr(ech);
909 return -EINVAL; 913 return -EINVAL;
@@ -981,7 +985,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
981 return err; 985 return err;
982 goto adjust_mean_ec; 986 goto adjust_mean_ec;
983 default: 987 default:
984 ubi_err("'ubi_io_read_vid_hdr()' returned unknown code %d", 988 ubi_err(ubi, "'ubi_io_read_vid_hdr()' returned unknown code %d",
985 err); 989 err);
986 return -EINVAL; 990 return -EINVAL;
987 } 991 }
@@ -999,7 +1003,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
999 case UBI_COMPAT_DELETE: 1003 case UBI_COMPAT_DELETE:
1000 if (vol_id != UBI_FM_SB_VOLUME_ID 1004 if (vol_id != UBI_FM_SB_VOLUME_ID
1001 && vol_id != UBI_FM_DATA_VOLUME_ID) { 1005 && vol_id != UBI_FM_DATA_VOLUME_ID) {
1002 ubi_msg("\"delete\" compatible internal volume %d:%d found, will remove it", 1006 ubi_msg(ubi, "\"delete\" compatible internal volume %d:%d found, will remove it",
1003 vol_id, lnum); 1007 vol_id, lnum);
1004 } 1008 }
1005 err = add_to_list(ai, pnum, vol_id, lnum, 1009 err = add_to_list(ai, pnum, vol_id, lnum,
@@ -1009,13 +1013,13 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
1009 return 0; 1013 return 0;
1010 1014
1011 case UBI_COMPAT_RO: 1015 case UBI_COMPAT_RO:
1012 ubi_msg("read-only compatible internal volume %d:%d found, switch to read-only mode", 1016 ubi_msg(ubi, "read-only compatible internal volume %d:%d found, switch to read-only mode",
1013 vol_id, lnum); 1017 vol_id, lnum);
1014 ubi->ro_mode = 1; 1018 ubi->ro_mode = 1;
1015 break; 1019 break;
1016 1020
1017 case UBI_COMPAT_PRESERVE: 1021 case UBI_COMPAT_PRESERVE:
1018 ubi_msg("\"preserve\" compatible internal volume %d:%d found", 1022 ubi_msg(ubi, "\"preserve\" compatible internal volume %d:%d found",
1019 vol_id, lnum); 1023 vol_id, lnum);
1020 err = add_to_list(ai, pnum, vol_id, lnum, 1024 err = add_to_list(ai, pnum, vol_id, lnum,
1021 ec, 0, &ai->alien); 1025 ec, 0, &ai->alien);
@@ -1024,14 +1028,14 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
1024 return 0; 1028 return 0;
1025 1029
1026 case UBI_COMPAT_REJECT: 1030 case UBI_COMPAT_REJECT:
1027 ubi_err("incompatible internal volume %d:%d found", 1031 ubi_err(ubi, "incompatible internal volume %d:%d found",
1028 vol_id, lnum); 1032 vol_id, lnum);
1029 return -EINVAL; 1033 return -EINVAL;
1030 } 1034 }
1031 } 1035 }
1032 1036
1033 if (ec_err) 1037 if (ec_err)
1034 ubi_warn("valid VID header but corrupted EC header at PEB %d", 1038 ubi_warn(ubi, "valid VID header but corrupted EC header at PEB %d",
1035 pnum); 1039 pnum);
1036 err = ubi_add_to_av(ubi, ai, pnum, ec, vidh, bitflips); 1040 err = ubi_add_to_av(ubi, ai, pnum, ec, vidh, bitflips);
1037 if (err) 1041 if (err)
@@ -1075,7 +1079,7 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
1075 * with the flash HW or driver. 1079 * with the flash HW or driver.
1076 */ 1080 */
1077 if (ai->corr_peb_count) { 1081 if (ai->corr_peb_count) {
1078 ubi_err("%d PEBs are corrupted and preserved", 1082 ubi_err(ubi, "%d PEBs are corrupted and preserved",
1079 ai->corr_peb_count); 1083 ai->corr_peb_count);
1080 pr_err("Corrupted PEBs are:"); 1084 pr_err("Corrupted PEBs are:");
1081 list_for_each_entry(aeb, &ai->corr, u.list) 1085 list_for_each_entry(aeb, &ai->corr, u.list)
@@ -1087,7 +1091,7 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
1087 * otherwise, only print a warning. 1091 * otherwise, only print a warning.
1088 */ 1092 */
1089 if (ai->corr_peb_count >= max_corr) { 1093 if (ai->corr_peb_count >= max_corr) {
1090 ubi_err("too many corrupted PEBs, refusing"); 1094 ubi_err(ubi, "too many corrupted PEBs, refusing");
1091 return -EINVAL; 1095 return -EINVAL;
1092 } 1096 }
1093 } 1097 }
@@ -1110,11 +1114,11 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
1110 */ 1114 */
1111 if (ai->maybe_bad_peb_count <= 2) { 1115 if (ai->maybe_bad_peb_count <= 2) {
1112 ai->is_empty = 1; 1116 ai->is_empty = 1;
1113 ubi_msg("empty MTD device detected"); 1117 ubi_msg(ubi, "empty MTD device detected");
1114 get_random_bytes(&ubi->image_seq, 1118 get_random_bytes(&ubi->image_seq,
1115 sizeof(ubi->image_seq)); 1119 sizeof(ubi->image_seq));
1116 } else { 1120 } else {
1117 ubi_err("MTD device is not UBI-formatted and possibly contains non-UBI data - refusing it"); 1121 ubi_err(ubi, "MTD device is not UBI-formatted and possibly contains non-UBI data - refusing it");
1118 return -EINVAL; 1122 return -EINVAL;
1119 } 1123 }
1120 1124
@@ -1248,7 +1252,7 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai,
1248 goto out_vidh; 1252 goto out_vidh;
1249 } 1253 }
1250 1254
1251 ubi_msg("scanning is finished"); 1255 ubi_msg(ubi, "scanning is finished");
1252 1256
1253 /* Calculate mean erase counter */ 1257 /* Calculate mean erase counter */
1254 if (ai->ec_count) 1258 if (ai->ec_count)
@@ -1515,37 +1519,37 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1515 vols_found += 1; 1519 vols_found += 1;
1516 1520
1517 if (ai->is_empty) { 1521 if (ai->is_empty) {
1518 ubi_err("bad is_empty flag"); 1522 ubi_err(ubi, "bad is_empty flag");
1519 goto bad_av; 1523 goto bad_av;
1520 } 1524 }
1521 1525
1522 if (av->vol_id < 0 || av->highest_lnum < 0 || 1526 if (av->vol_id < 0 || av->highest_lnum < 0 ||
1523 av->leb_count < 0 || av->vol_type < 0 || av->used_ebs < 0 || 1527 av->leb_count < 0 || av->vol_type < 0 || av->used_ebs < 0 ||
1524 av->data_pad < 0 || av->last_data_size < 0) { 1528 av->data_pad < 0 || av->last_data_size < 0) {
1525 ubi_err("negative values"); 1529 ubi_err(ubi, "negative values");
1526 goto bad_av; 1530 goto bad_av;
1527 } 1531 }
1528 1532
1529 if (av->vol_id >= UBI_MAX_VOLUMES && 1533 if (av->vol_id >= UBI_MAX_VOLUMES &&
1530 av->vol_id < UBI_INTERNAL_VOL_START) { 1534 av->vol_id < UBI_INTERNAL_VOL_START) {
1531 ubi_err("bad vol_id"); 1535 ubi_err(ubi, "bad vol_id");
1532 goto bad_av; 1536 goto bad_av;
1533 } 1537 }
1534 1538
1535 if (av->vol_id > ai->highest_vol_id) { 1539 if (av->vol_id > ai->highest_vol_id) {
1536 ubi_err("highest_vol_id is %d, but vol_id %d is there", 1540 ubi_err(ubi, "highest_vol_id is %d, but vol_id %d is there",
1537 ai->highest_vol_id, av->vol_id); 1541 ai->highest_vol_id, av->vol_id);
1538 goto out; 1542 goto out;
1539 } 1543 }
1540 1544
1541 if (av->vol_type != UBI_DYNAMIC_VOLUME && 1545 if (av->vol_type != UBI_DYNAMIC_VOLUME &&
1542 av->vol_type != UBI_STATIC_VOLUME) { 1546 av->vol_type != UBI_STATIC_VOLUME) {
1543 ubi_err("bad vol_type"); 1547 ubi_err(ubi, "bad vol_type");
1544 goto bad_av; 1548 goto bad_av;
1545 } 1549 }
1546 1550
1547 if (av->data_pad > ubi->leb_size / 2) { 1551 if (av->data_pad > ubi->leb_size / 2) {
1548 ubi_err("bad data_pad"); 1552 ubi_err(ubi, "bad data_pad");
1549 goto bad_av; 1553 goto bad_av;
1550 } 1554 }
1551 1555
@@ -1557,48 +1561,48 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1557 leb_count += 1; 1561 leb_count += 1;
1558 1562
1559 if (aeb->pnum < 0 || aeb->ec < 0) { 1563 if (aeb->pnum < 0 || aeb->ec < 0) {
1560 ubi_err("negative values"); 1564 ubi_err(ubi, "negative values");
1561 goto bad_aeb; 1565 goto bad_aeb;
1562 } 1566 }
1563 1567
1564 if (aeb->ec < ai->min_ec) { 1568 if (aeb->ec < ai->min_ec) {
1565 ubi_err("bad ai->min_ec (%d), %d found", 1569 ubi_err(ubi, "bad ai->min_ec (%d), %d found",
1566 ai->min_ec, aeb->ec); 1570 ai->min_ec, aeb->ec);
1567 goto bad_aeb; 1571 goto bad_aeb;
1568 } 1572 }
1569 1573
1570 if (aeb->ec > ai->max_ec) { 1574 if (aeb->ec > ai->max_ec) {
1571 ubi_err("bad ai->max_ec (%d), %d found", 1575 ubi_err(ubi, "bad ai->max_ec (%d), %d found",
1572 ai->max_ec, aeb->ec); 1576 ai->max_ec, aeb->ec);
1573 goto bad_aeb; 1577 goto bad_aeb;
1574 } 1578 }
1575 1579
1576 if (aeb->pnum >= ubi->peb_count) { 1580 if (aeb->pnum >= ubi->peb_count) {
1577 ubi_err("too high PEB number %d, total PEBs %d", 1581 ubi_err(ubi, "too high PEB number %d, total PEBs %d",
1578 aeb->pnum, ubi->peb_count); 1582 aeb->pnum, ubi->peb_count);
1579 goto bad_aeb; 1583 goto bad_aeb;
1580 } 1584 }
1581 1585
1582 if (av->vol_type == UBI_STATIC_VOLUME) { 1586 if (av->vol_type == UBI_STATIC_VOLUME) {
1583 if (aeb->lnum >= av->used_ebs) { 1587 if (aeb->lnum >= av->used_ebs) {
1584 ubi_err("bad lnum or used_ebs"); 1588 ubi_err(ubi, "bad lnum or used_ebs");
1585 goto bad_aeb; 1589 goto bad_aeb;
1586 } 1590 }
1587 } else { 1591 } else {
1588 if (av->used_ebs != 0) { 1592 if (av->used_ebs != 0) {
1589 ubi_err("non-zero used_ebs"); 1593 ubi_err(ubi, "non-zero used_ebs");
1590 goto bad_aeb; 1594 goto bad_aeb;
1591 } 1595 }
1592 } 1596 }
1593 1597
1594 if (aeb->lnum > av->highest_lnum) { 1598 if (aeb->lnum > av->highest_lnum) {
1595 ubi_err("incorrect highest_lnum or lnum"); 1599 ubi_err(ubi, "incorrect highest_lnum or lnum");
1596 goto bad_aeb; 1600 goto bad_aeb;
1597 } 1601 }
1598 } 1602 }
1599 1603
1600 if (av->leb_count != leb_count) { 1604 if (av->leb_count != leb_count) {
1601 ubi_err("bad leb_count, %d objects in the tree", 1605 ubi_err(ubi, "bad leb_count, %d objects in the tree",
1602 leb_count); 1606 leb_count);
1603 goto bad_av; 1607 goto bad_av;
1604 } 1608 }
@@ -1609,13 +1613,13 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1609 aeb = last_aeb; 1613 aeb = last_aeb;
1610 1614
1611 if (aeb->lnum != av->highest_lnum) { 1615 if (aeb->lnum != av->highest_lnum) {
1612 ubi_err("bad highest_lnum"); 1616 ubi_err(ubi, "bad highest_lnum");
1613 goto bad_aeb; 1617 goto bad_aeb;
1614 } 1618 }
1615 } 1619 }
1616 1620
1617 if (vols_found != ai->vols_found) { 1621 if (vols_found != ai->vols_found) {
1618 ubi_err("bad ai->vols_found %d, should be %d", 1622 ubi_err(ubi, "bad ai->vols_found %d, should be %d",
1619 ai->vols_found, vols_found); 1623 ai->vols_found, vols_found);
1620 goto out; 1624 goto out;
1621 } 1625 }
@@ -1632,7 +1636,8 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1632 1636
1633 err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidh, 1); 1637 err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidh, 1);
1634 if (err && err != UBI_IO_BITFLIPS) { 1638 if (err && err != UBI_IO_BITFLIPS) {
1635 ubi_err("VID header is not OK (%d)", err); 1639 ubi_err(ubi, "VID header is not OK (%d)",
1640 err);
1636 if (err > 0) 1641 if (err > 0)
1637 err = -EIO; 1642 err = -EIO;
1638 return err; 1643 return err;
@@ -1641,37 +1646,37 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1641 vol_type = vidh->vol_type == UBI_VID_DYNAMIC ? 1646 vol_type = vidh->vol_type == UBI_VID_DYNAMIC ?
1642 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; 1647 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
1643 if (av->vol_type != vol_type) { 1648 if (av->vol_type != vol_type) {
1644 ubi_err("bad vol_type"); 1649 ubi_err(ubi, "bad vol_type");
1645 goto bad_vid_hdr; 1650 goto bad_vid_hdr;
1646 } 1651 }
1647 1652
1648 if (aeb->sqnum != be64_to_cpu(vidh->sqnum)) { 1653 if (aeb->sqnum != be64_to_cpu(vidh->sqnum)) {
1649 ubi_err("bad sqnum %llu", aeb->sqnum); 1654 ubi_err(ubi, "bad sqnum %llu", aeb->sqnum);
1650 goto bad_vid_hdr; 1655 goto bad_vid_hdr;
1651 } 1656 }
1652 1657
1653 if (av->vol_id != be32_to_cpu(vidh->vol_id)) { 1658 if (av->vol_id != be32_to_cpu(vidh->vol_id)) {
1654 ubi_err("bad vol_id %d", av->vol_id); 1659 ubi_err(ubi, "bad vol_id %d", av->vol_id);
1655 goto bad_vid_hdr; 1660 goto bad_vid_hdr;
1656 } 1661 }
1657 1662
1658 if (av->compat != vidh->compat) { 1663 if (av->compat != vidh->compat) {
1659 ubi_err("bad compat %d", vidh->compat); 1664 ubi_err(ubi, "bad compat %d", vidh->compat);
1660 goto bad_vid_hdr; 1665 goto bad_vid_hdr;
1661 } 1666 }
1662 1667
1663 if (aeb->lnum != be32_to_cpu(vidh->lnum)) { 1668 if (aeb->lnum != be32_to_cpu(vidh->lnum)) {
1664 ubi_err("bad lnum %d", aeb->lnum); 1669 ubi_err(ubi, "bad lnum %d", aeb->lnum);
1665 goto bad_vid_hdr; 1670 goto bad_vid_hdr;
1666 } 1671 }
1667 1672
1668 if (av->used_ebs != be32_to_cpu(vidh->used_ebs)) { 1673 if (av->used_ebs != be32_to_cpu(vidh->used_ebs)) {
1669 ubi_err("bad used_ebs %d", av->used_ebs); 1674 ubi_err(ubi, "bad used_ebs %d", av->used_ebs);
1670 goto bad_vid_hdr; 1675 goto bad_vid_hdr;
1671 } 1676 }
1672 1677
1673 if (av->data_pad != be32_to_cpu(vidh->data_pad)) { 1678 if (av->data_pad != be32_to_cpu(vidh->data_pad)) {
1674 ubi_err("bad data_pad %d", av->data_pad); 1679 ubi_err(ubi, "bad data_pad %d", av->data_pad);
1675 goto bad_vid_hdr; 1680 goto bad_vid_hdr;
1676 } 1681 }
1677 } 1682 }
@@ -1680,12 +1685,13 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1680 continue; 1685 continue;
1681 1686
1682 if (av->highest_lnum != be32_to_cpu(vidh->lnum)) { 1687 if (av->highest_lnum != be32_to_cpu(vidh->lnum)) {
1683 ubi_err("bad highest_lnum %d", av->highest_lnum); 1688 ubi_err(ubi, "bad highest_lnum %d", av->highest_lnum);
1684 goto bad_vid_hdr; 1689 goto bad_vid_hdr;
1685 } 1690 }
1686 1691
1687 if (av->last_data_size != be32_to_cpu(vidh->data_size)) { 1692 if (av->last_data_size != be32_to_cpu(vidh->data_size)) {
1688 ubi_err("bad last_data_size %d", av->last_data_size); 1693 ubi_err(ubi, "bad last_data_size %d",
1694 av->last_data_size);
1689 goto bad_vid_hdr; 1695 goto bad_vid_hdr;
1690 } 1696 }
1691 } 1697 }
@@ -1726,7 +1732,7 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1726 err = 0; 1732 err = 0;
1727 for (pnum = 0; pnum < ubi->peb_count; pnum++) 1733 for (pnum = 0; pnum < ubi->peb_count; pnum++)
1728 if (!buf[pnum]) { 1734 if (!buf[pnum]) {
1729 ubi_err("PEB %d is not referred", pnum); 1735 ubi_err(ubi, "PEB %d is not referred", pnum);
1730 err = 1; 1736 err = 1;
1731 } 1737 }
1732 1738
@@ -1736,18 +1742,18 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
1736 return 0; 1742 return 0;
1737 1743
1738bad_aeb: 1744bad_aeb:
1739 ubi_err("bad attaching information about LEB %d", aeb->lnum); 1745 ubi_err(ubi, "bad attaching information about LEB %d", aeb->lnum);
1740 ubi_dump_aeb(aeb, 0); 1746 ubi_dump_aeb(aeb, 0);
1741 ubi_dump_av(av); 1747 ubi_dump_av(av);
1742 goto out; 1748 goto out;
1743 1749
1744bad_av: 1750bad_av:
1745 ubi_err("bad attaching information about volume %d", av->vol_id); 1751 ubi_err(ubi, "bad attaching information about volume %d", av->vol_id);
1746 ubi_dump_av(av); 1752 ubi_dump_av(av);
1747 goto out; 1753 goto out;
1748 1754
1749bad_vid_hdr: 1755bad_vid_hdr:
1750 ubi_err("bad attaching information about volume %d", av->vol_id); 1756 ubi_err(ubi, "bad attaching information about volume %d", av->vol_id);
1751 ubi_dump_av(av); 1757 ubi_dump_av(av);
1752 ubi_dump_vid_hdr(vidh); 1758 ubi_dump_vid_hdr(vidh);
1753 1759
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 8876c7d3d712..6b6bce28bd63 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -111,13 +111,13 @@ static int __init ubiblock_set_param(const char *val,
111 111
112 len = strnlen(val, UBIBLOCK_PARAM_LEN); 112 len = strnlen(val, UBIBLOCK_PARAM_LEN);
113 if (len == 0) { 113 if (len == 0) {
114 ubi_warn("block: empty 'block=' parameter - ignored\n"); 114 pr_warn("UBI: block: empty 'block=' parameter - ignored\n");
115 return 0; 115 return 0;
116 } 116 }
117 117
118 if (len == UBIBLOCK_PARAM_LEN) { 118 if (len == UBIBLOCK_PARAM_LEN) {
119 ubi_err("block: parameter \"%s\" is too long, max. is %d\n", 119 pr_err("UBI: block: parameter \"%s\" is too long, max. is %d\n",
120 val, UBIBLOCK_PARAM_LEN); 120 val, UBIBLOCK_PARAM_LEN);
121 return -EINVAL; 121 return -EINVAL;
122 } 122 }
123 123
@@ -188,9 +188,8 @@ static int ubiblock_read_to_buf(struct ubiblock *dev, char *buffer,
188 188
189 ret = ubi_read(dev->desc, leb, buffer, offset, len); 189 ret = ubi_read(dev->desc, leb, buffer, offset, len);
190 if (ret) { 190 if (ret) {
191 ubi_err("%s: error %d while reading from LEB %d (offset %d, " 191 dev_err(disk_to_dev(dev->gd), "%d while reading from LEB %d (offset %d, length %d)",
192 "length %d)", dev->gd->disk_name, ret, leb, offset, 192 ret, leb, offset, len);
193 len);
194 return ret; 193 return ret;
195 } 194 }
196 return 0; 195 return 0;
@@ -328,8 +327,8 @@ static int ubiblock_open(struct block_device *bdev, fmode_t mode)
328 327
329 dev->desc = ubi_open_volume(dev->ubi_num, dev->vol_id, UBI_READONLY); 328 dev->desc = ubi_open_volume(dev->ubi_num, dev->vol_id, UBI_READONLY);
330 if (IS_ERR(dev->desc)) { 329 if (IS_ERR(dev->desc)) {
331 ubi_err("%s failed to open ubi volume %d_%d", 330 dev_err(disk_to_dev(dev->gd), "failed to open ubi volume %d_%d",
332 dev->gd->disk_name, dev->ubi_num, dev->vol_id); 331 dev->ubi_num, dev->vol_id);
333 ret = PTR_ERR(dev->desc); 332 ret = PTR_ERR(dev->desc);
334 dev->desc = NULL; 333 dev->desc = NULL;
335 goto out_unlock; 334 goto out_unlock;
@@ -405,7 +404,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
405 /* Initialize the gendisk of this ubiblock device */ 404 /* Initialize the gendisk of this ubiblock device */
406 gd = alloc_disk(1); 405 gd = alloc_disk(1);
407 if (!gd) { 406 if (!gd) {
408 ubi_err("block: alloc_disk failed"); 407 pr_err("UBI: block: alloc_disk failed");
409 ret = -ENODEV; 408 ret = -ENODEV;
410 goto out_free_dev; 409 goto out_free_dev;
411 } 410 }
@@ -421,7 +420,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
421 spin_lock_init(&dev->queue_lock); 420 spin_lock_init(&dev->queue_lock);
422 dev->rq = blk_init_queue(ubiblock_request, &dev->queue_lock); 421 dev->rq = blk_init_queue(ubiblock_request, &dev->queue_lock);
423 if (!dev->rq) { 422 if (!dev->rq) {
424 ubi_err("block: blk_init_queue failed"); 423 dev_err(disk_to_dev(gd), "blk_init_queue failed");
425 ret = -ENODEV; 424 ret = -ENODEV;
426 goto out_put_disk; 425 goto out_put_disk;
427 } 426 }
@@ -446,8 +445,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
446 445
447 /* Must be the last step: anyone can call file ops from now on */ 446 /* Must be the last step: anyone can call file ops from now on */
448 add_disk(dev->gd); 447 add_disk(dev->gd);
449 ubi_msg("%s created from ubi%d:%d(%s)", 448 dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
450 dev->gd->disk_name, dev->ubi_num, dev->vol_id, vi->name); 449 dev->ubi_num, dev->vol_id, vi->name);
451 return 0; 450 return 0;
452 451
453out_free_queue: 452out_free_queue:
@@ -464,7 +463,7 @@ static void ubiblock_cleanup(struct ubiblock *dev)
464{ 463{
465 del_gendisk(dev->gd); 464 del_gendisk(dev->gd);
466 blk_cleanup_queue(dev->rq); 465 blk_cleanup_queue(dev->rq);
467 ubi_msg("%s released", dev->gd->disk_name); 466 dev_info(disk_to_dev(dev->gd), "released");
468 put_disk(dev->gd); 467 put_disk(dev->gd);
469} 468}
470 469
@@ -518,8 +517,8 @@ static int ubiblock_resize(struct ubi_volume_info *vi)
518 } 517 }
519 if ((sector_t)disk_capacity != disk_capacity) { 518 if ((sector_t)disk_capacity != disk_capacity) {
520 mutex_unlock(&devices_mutex); 519 mutex_unlock(&devices_mutex);
521 ubi_warn("%s: the volume is too big (%d LEBs), cannot resize", 520 dev_warn(disk_to_dev(dev->gd), "the volume is too big (%d LEBs), cannot resize",
522 dev->gd->disk_name, vi->size); 521 vi->size);
523 return -EFBIG; 522 return -EFBIG;
524 } 523 }
525 524
@@ -527,8 +526,8 @@ static int ubiblock_resize(struct ubi_volume_info *vi)
527 526
528 if (get_capacity(dev->gd) != disk_capacity) { 527 if (get_capacity(dev->gd) != disk_capacity) {
529 set_capacity(dev->gd, disk_capacity); 528 set_capacity(dev->gd, disk_capacity);
530 ubi_msg("%s resized to %lld bytes", dev->gd->disk_name, 529 dev_info(disk_to_dev(dev->gd), "resized to %lld bytes",
531 vi->used_bytes); 530 vi->used_bytes);
532 } 531 }
533 mutex_unlock(&dev->dev_mutex); 532 mutex_unlock(&dev->dev_mutex);
534 mutex_unlock(&devices_mutex); 533 mutex_unlock(&devices_mutex);
@@ -596,8 +595,8 @@ static int __init ubiblock_create_from_param(void)
596 595
597 desc = open_volume_desc(p->name, p->ubi_num, p->vol_id); 596 desc = open_volume_desc(p->name, p->ubi_num, p->vol_id);
598 if (IS_ERR(desc)) { 597 if (IS_ERR(desc)) {
599 ubi_err("block: can't open volume, err=%ld\n", 598 pr_err("UBI: block: can't open volume, err=%ld\n",
600 PTR_ERR(desc)); 599 PTR_ERR(desc));
601 ret = PTR_ERR(desc); 600 ret = PTR_ERR(desc);
602 break; 601 break;
603 } 602 }
@@ -607,8 +606,8 @@ static int __init ubiblock_create_from_param(void)
607 606
608 ret = ubiblock_create(&vi); 607 ret = ubiblock_create(&vi);
609 if (ret) { 608 if (ret) {
610 ubi_err("block: can't add '%s' volume, err=%d\n", 609 pr_err("UBI: block: can't add '%s' volume, err=%d\n",
611 vi.name, ret); 610 vi.name, ret);
612 break; 611 break;
613 } 612 }
614 } 613 }
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 6e30a3c280d0..3405be46ebe9 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -166,7 +166,7 @@ int ubi_volume_notify(struct ubi_device *ubi, struct ubi_volume *vol, int ntype)
166 case UBI_VOLUME_RESIZED: 166 case UBI_VOLUME_RESIZED:
167 case UBI_VOLUME_RENAMED: 167 case UBI_VOLUME_RENAMED:
168 if (ubi_update_fastmap(ubi)) { 168 if (ubi_update_fastmap(ubi)) {
169 ubi_err("Unable to update fastmap!"); 169 ubi_err(ubi, "Unable to update fastmap!");
170 ubi_ro_mode(ubi); 170 ubi_ro_mode(ubi);
171 } 171 }
172 } 172 }
@@ -517,7 +517,7 @@ static int uif_init(struct ubi_device *ubi, int *ref)
517 */ 517 */
518 err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name); 518 err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name);
519 if (err) { 519 if (err) {
520 ubi_err("cannot register UBI character devices"); 520 ubi_err(ubi, "cannot register UBI character devices");
521 return err; 521 return err;
522 } 522 }
523 523
@@ -528,7 +528,7 @@ static int uif_init(struct ubi_device *ubi, int *ref)
528 528
529 err = cdev_add(&ubi->cdev, dev, 1); 529 err = cdev_add(&ubi->cdev, dev, 1);
530 if (err) { 530 if (err) {
531 ubi_err("cannot add character device"); 531 ubi_err(ubi, "cannot add character device");
532 goto out_unreg; 532 goto out_unreg;
533 } 533 }
534 534
@@ -540,7 +540,7 @@ static int uif_init(struct ubi_device *ubi, int *ref)
540 if (ubi->volumes[i]) { 540 if (ubi->volumes[i]) {
541 err = ubi_add_volume(ubi, ubi->volumes[i]); 541 err = ubi_add_volume(ubi, ubi->volumes[i]);
542 if (err) { 542 if (err) {
543 ubi_err("cannot add volume %d", i); 543 ubi_err(ubi, "cannot add volume %d", i);
544 goto out_volumes; 544 goto out_volumes;
545 } 545 }
546 } 546 }
@@ -556,7 +556,8 @@ out_sysfs:
556 cdev_del(&ubi->cdev); 556 cdev_del(&ubi->cdev);
557out_unreg: 557out_unreg:
558 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 558 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
559 ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err); 559 ubi_err(ubi, "cannot initialize UBI %s, error %d",
560 ubi->ubi_name, err);
560 return err; 561 return err;
561} 562}
562 563
@@ -650,7 +651,7 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
650 * guess we should just pick the largest region. But this is 651 * guess we should just pick the largest region. But this is
651 * not implemented. 652 * not implemented.
652 */ 653 */
653 ubi_err("multiple regions, not implemented"); 654 ubi_err(ubi, "multiple regions, not implemented");
654 return -EINVAL; 655 return -EINVAL;
655 } 656 }
656 657
@@ -685,7 +686,7 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
685 * which allows us to avoid costly division operations. 686 * which allows us to avoid costly division operations.
686 */ 687 */
687 if (!is_power_of_2(ubi->min_io_size)) { 688 if (!is_power_of_2(ubi->min_io_size)) {
688 ubi_err("min. I/O unit (%d) is not power of 2", 689 ubi_err(ubi, "min. I/O unit (%d) is not power of 2",
689 ubi->min_io_size); 690 ubi->min_io_size);
690 return -EINVAL; 691 return -EINVAL;
691 } 692 }
@@ -702,7 +703,7 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
702 if (ubi->max_write_size < ubi->min_io_size || 703 if (ubi->max_write_size < ubi->min_io_size ||
703 ubi->max_write_size % ubi->min_io_size || 704 ubi->max_write_size % ubi->min_io_size ||
704 !is_power_of_2(ubi->max_write_size)) { 705 !is_power_of_2(ubi->max_write_size)) {
705 ubi_err("bad write buffer size %d for %d min. I/O unit", 706 ubi_err(ubi, "bad write buffer size %d for %d min. I/O unit",
706 ubi->max_write_size, ubi->min_io_size); 707 ubi->max_write_size, ubi->min_io_size);
707 return -EINVAL; 708 return -EINVAL;
708 } 709 }
@@ -739,7 +740,7 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
739 740
740 /* The shift must be aligned to 32-bit boundary */ 741 /* The shift must be aligned to 32-bit boundary */
741 if (ubi->vid_hdr_shift % 4) { 742 if (ubi->vid_hdr_shift % 4) {
742 ubi_err("unaligned VID header shift %d", 743 ubi_err(ubi, "unaligned VID header shift %d",
743 ubi->vid_hdr_shift); 744 ubi->vid_hdr_shift);
744 return -EINVAL; 745 return -EINVAL;
745 } 746 }
@@ -749,7 +750,7 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
749 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || 750 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE ||
750 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || 751 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE ||
751 ubi->leb_start & (ubi->min_io_size - 1)) { 752 ubi->leb_start & (ubi->min_io_size - 1)) {
752 ubi_err("bad VID header (%d) or data offsets (%d)", 753 ubi_err(ubi, "bad VID header (%d) or data offsets (%d)",
753 ubi->vid_hdr_offset, ubi->leb_start); 754 ubi->vid_hdr_offset, ubi->leb_start);
754 return -EINVAL; 755 return -EINVAL;
755 } 756 }
@@ -769,14 +770,14 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
769 * read-only mode. 770 * read-only mode.
770 */ 771 */
771 if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) { 772 if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) {
772 ubi_warn("EC and VID headers are in the same minimal I/O unit, switch to read-only mode"); 773 ubi_warn(ubi, "EC and VID headers are in the same minimal I/O unit, switch to read-only mode");
773 ubi->ro_mode = 1; 774 ubi->ro_mode = 1;
774 } 775 }
775 776
776 ubi->leb_size = ubi->peb_size - ubi->leb_start; 777 ubi->leb_size = ubi->peb_size - ubi->leb_start;
777 778
778 if (!(ubi->mtd->flags & MTD_WRITEABLE)) { 779 if (!(ubi->mtd->flags & MTD_WRITEABLE)) {
779 ubi_msg("MTD device %d is write-protected, attach in read-only mode", 780 ubi_msg(ubi, "MTD device %d is write-protected, attach in read-only mode",
780 ubi->mtd->index); 781 ubi->mtd->index);
781 ubi->ro_mode = 1; 782 ubi->ro_mode = 1;
782 } 783 }
@@ -809,7 +810,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
809 int err, old_reserved_pebs = vol->reserved_pebs; 810 int err, old_reserved_pebs = vol->reserved_pebs;
810 811
811 if (ubi->ro_mode) { 812 if (ubi->ro_mode) {
812 ubi_warn("skip auto-resize because of R/O mode"); 813 ubi_warn(ubi, "skip auto-resize because of R/O mode");
813 return 0; 814 return 0;
814 } 815 }
815 816
@@ -830,21 +831,22 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
830 vtbl_rec = ubi->vtbl[vol_id]; 831 vtbl_rec = ubi->vtbl[vol_id];
831 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 832 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
832 if (err) 833 if (err)
833 ubi_err("cannot clean auto-resize flag for volume %d", 834 ubi_err(ubi, "cannot clean auto-resize flag for volume %d",
834 vol_id); 835 vol_id);
835 } else { 836 } else {
836 desc.vol = vol; 837 desc.vol = vol;
837 err = ubi_resize_volume(&desc, 838 err = ubi_resize_volume(&desc,
838 old_reserved_pebs + ubi->avail_pebs); 839 old_reserved_pebs + ubi->avail_pebs);
839 if (err) 840 if (err)
840 ubi_err("cannot auto-resize volume %d", vol_id); 841 ubi_err(ubi, "cannot auto-resize volume %d",
842 vol_id);
841 } 843 }
842 844
843 if (err) 845 if (err)
844 return err; 846 return err;
845 847
846 ubi_msg("volume %d (\"%s\") re-sized from %d to %d LEBs", vol_id, 848 ubi_msg(ubi, "volume %d (\"%s\") re-sized from %d to %d LEBs",
847 vol->name, old_reserved_pebs, vol->reserved_pebs); 849 vol_id, vol->name, old_reserved_pebs, vol->reserved_pebs);
848 return 0; 850 return 0;
849} 851}
850 852
@@ -885,7 +887,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
885 for (i = 0; i < UBI_MAX_DEVICES; i++) { 887 for (i = 0; i < UBI_MAX_DEVICES; i++) {
886 ubi = ubi_devices[i]; 888 ubi = ubi_devices[i];
887 if (ubi && mtd->index == ubi->mtd->index) { 889 if (ubi && mtd->index == ubi->mtd->index) {
888 ubi_err("mtd%d is already attached to ubi%d", 890 ubi_err(ubi, "mtd%d is already attached to ubi%d",
889 mtd->index, i); 891 mtd->index, i);
890 return -EEXIST; 892 return -EEXIST;
891 } 893 }
@@ -900,7 +902,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
900 * no sense to attach emulated MTD devices, so we prohibit this. 902 * no sense to attach emulated MTD devices, so we prohibit this.
901 */ 903 */
902 if (mtd->type == MTD_UBIVOLUME) { 904 if (mtd->type == MTD_UBIVOLUME) {
903 ubi_err("refuse attaching mtd%d - it is already emulated on top of UBI", 905 ubi_err(ubi, "refuse attaching mtd%d - it is already emulated on top of UBI",
904 mtd->index); 906 mtd->index);
905 return -EINVAL; 907 return -EINVAL;
906 } 908 }
@@ -911,7 +913,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
911 if (!ubi_devices[ubi_num]) 913 if (!ubi_devices[ubi_num])
912 break; 914 break;
913 if (ubi_num == UBI_MAX_DEVICES) { 915 if (ubi_num == UBI_MAX_DEVICES) {
914 ubi_err("only %d UBI devices may be created", 916 ubi_err(ubi, "only %d UBI devices may be created",
915 UBI_MAX_DEVICES); 917 UBI_MAX_DEVICES);
916 return -ENFILE; 918 return -ENFILE;
917 } 919 }
@@ -921,7 +923,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
921 923
922 /* Make sure ubi_num is not busy */ 924 /* Make sure ubi_num is not busy */
923 if (ubi_devices[ubi_num]) { 925 if (ubi_devices[ubi_num]) {
924 ubi_err("ubi%d already exists", ubi_num); 926 ubi_err(ubi, "ubi%d already exists", ubi_num);
925 return -EEXIST; 927 return -EEXIST;
926 } 928 }
927 } 929 }
@@ -953,13 +955,14 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
953 955
954 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) 956 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd)
955 <= UBI_FM_MAX_START) { 957 <= UBI_FM_MAX_START) {
956 ubi_err("More than %i PEBs are needed for fastmap, sorry.", 958 ubi_err(ubi, "More than %i PEBs are needed for fastmap, sorry.",
957 UBI_FM_MAX_START); 959 UBI_FM_MAX_START);
958 ubi->fm_disabled = 1; 960 ubi->fm_disabled = 1;
959 } 961 }
960 962
961 ubi_msg("default fastmap pool size: %d", ubi->fm_pool.max_size); 963 ubi_msg(ubi, "default fastmap pool size: %d", ubi->fm_pool.max_size);
962 ubi_msg("default fastmap WL pool size: %d", ubi->fm_wl_pool.max_size); 964 ubi_msg(ubi, "default fastmap WL pool size: %d",
965 ubi->fm_wl_pool.max_size);
963#else 966#else
964 ubi->fm_disabled = 1; 967 ubi->fm_disabled = 1;
965#endif 968#endif
@@ -970,7 +973,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
970 mutex_init(&ubi->fm_mutex); 973 mutex_init(&ubi->fm_mutex);
971 init_rwsem(&ubi->fm_sem); 974 init_rwsem(&ubi->fm_sem);
972 975
973 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); 976 ubi_msg(ubi, "attaching mtd%d to ubi%d", mtd->index, ubi_num);
974 977
975 err = io_init(ubi, max_beb_per1024); 978 err = io_init(ubi, max_beb_per1024);
976 if (err) 979 if (err)
@@ -989,7 +992,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
989#endif 992#endif
990 err = ubi_attach(ubi, 0); 993 err = ubi_attach(ubi, 0);
991 if (err) { 994 if (err) {
992 ubi_err("failed to attach mtd%d, error %d", mtd->index, err); 995 ubi_err(ubi, "failed to attach mtd%d, error %d",
996 mtd->index, err);
993 goto out_free; 997 goto out_free;
994 } 998 }
995 999
@@ -1010,28 +1014,28 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
1010 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name); 1014 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name);
1011 if (IS_ERR(ubi->bgt_thread)) { 1015 if (IS_ERR(ubi->bgt_thread)) {
1012 err = PTR_ERR(ubi->bgt_thread); 1016 err = PTR_ERR(ubi->bgt_thread);
1013 ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name, 1017 ubi_err(ubi, "cannot spawn \"%s\", error %d",
1014 err); 1018 ubi->bgt_name, err);
1015 goto out_debugfs; 1019 goto out_debugfs;
1016 } 1020 }
1017 1021
1018 ubi_msg("attached mtd%d (name \"%s\", size %llu MiB) to ubi%d", 1022 ubi_msg(ubi, "attached mtd%d (name \"%s\", size %llu MiB)",
1019 mtd->index, mtd->name, ubi->flash_size >> 20, ubi_num); 1023 mtd->index, mtd->name, ubi->flash_size >> 20);
1020 ubi_msg("PEB size: %d bytes (%d KiB), LEB size: %d bytes", 1024 ubi_msg(ubi, "PEB size: %d bytes (%d KiB), LEB size: %d bytes",
1021 ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size); 1025 ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size);
1022 ubi_msg("min./max. I/O unit sizes: %d/%d, sub-page size %d", 1026 ubi_msg(ubi, "min./max. I/O unit sizes: %d/%d, sub-page size %d",
1023 ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size); 1027 ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size);
1024 ubi_msg("VID header offset: %d (aligned %d), data offset: %d", 1028 ubi_msg(ubi, "VID header offset: %d (aligned %d), data offset: %d",
1025 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start); 1029 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start);
1026 ubi_msg("good PEBs: %d, bad PEBs: %d, corrupted PEBs: %d", 1030 ubi_msg(ubi, "good PEBs: %d, bad PEBs: %d, corrupted PEBs: %d",
1027 ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count); 1031 ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count);
1028 ubi_msg("user volume: %d, internal volumes: %d, max. volumes count: %d", 1032 ubi_msg(ubi, "user volume: %d, internal volumes: %d, max. volumes count: %d",
1029 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT, 1033 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT,
1030 ubi->vtbl_slots); 1034 ubi->vtbl_slots);
1031 ubi_msg("max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u", 1035 ubi_msg(ubi, "max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u",
1032 ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD, 1036 ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD,
1033 ubi->image_seq); 1037 ubi->image_seq);
1034 ubi_msg("available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d", 1038 ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d",
1035 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs); 1039 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs);
1036 1040
1037 /* 1041 /*
@@ -1100,7 +1104,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1100 return -EBUSY; 1104 return -EBUSY;
1101 } 1105 }
1102 /* This may only happen if there is a bug */ 1106 /* This may only happen if there is a bug */
1103 ubi_err("%s reference count %d, destroy anyway", 1107 ubi_err(ubi, "%s reference count %d, destroy anyway",
1104 ubi->ubi_name, ubi->ref_count); 1108 ubi->ubi_name, ubi->ref_count);
1105 } 1109 }
1106 ubi_devices[ubi_num] = NULL; 1110 ubi_devices[ubi_num] = NULL;
@@ -1108,7 +1112,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1108 1112
1109 ubi_assert(ubi_num == ubi->ubi_num); 1113 ubi_assert(ubi_num == ubi->ubi_num);
1110 ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); 1114 ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
1111 ubi_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num); 1115 ubi_msg(ubi, "detaching mtd%d", ubi->mtd->index);
1112#ifdef CONFIG_MTD_UBI_FASTMAP 1116#ifdef CONFIG_MTD_UBI_FASTMAP
1113 /* If we don't write a new fastmap at detach time we lose all 1117 /* If we don't write a new fastmap at detach time we lose all
1114 * EC updates that have been made since the last written fastmap. */ 1118 * EC updates that have been made since the last written fastmap. */
@@ -1136,7 +1140,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1136 put_mtd_device(ubi->mtd); 1140 put_mtd_device(ubi->mtd);
1137 vfree(ubi->peb_buf); 1141 vfree(ubi->peb_buf);
1138 vfree(ubi->fm_buf); 1142 vfree(ubi->fm_buf);
1139 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); 1143 ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index);
1140 put_device(&ubi->dev); 1144 put_device(&ubi->dev);
1141 return 0; 1145 return 0;
1142} 1146}
@@ -1218,7 +1222,8 @@ static int __init ubi_init(void)
1218 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); 1222 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);
1219 1223
1220 if (mtd_devs > UBI_MAX_DEVICES) { 1224 if (mtd_devs > UBI_MAX_DEVICES) {
1221 ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES); 1225 pr_err("UBI error: too many MTD devices, maximum is %d",
1226 UBI_MAX_DEVICES);
1222 return -EINVAL; 1227 return -EINVAL;
1223 } 1228 }
1224 1229
@@ -1226,19 +1231,19 @@ static int __init ubi_init(void)
1226 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); 1231 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
1227 if (IS_ERR(ubi_class)) { 1232 if (IS_ERR(ubi_class)) {
1228 err = PTR_ERR(ubi_class); 1233 err = PTR_ERR(ubi_class);
1229 ubi_err("cannot create UBI class"); 1234 pr_err("UBI error: cannot create UBI class");
1230 goto out; 1235 goto out;
1231 } 1236 }
1232 1237
1233 err = class_create_file(ubi_class, &ubi_version); 1238 err = class_create_file(ubi_class, &ubi_version);
1234 if (err) { 1239 if (err) {
1235 ubi_err("cannot create sysfs file"); 1240 pr_err("UBI error: cannot create sysfs file");
1236 goto out_class; 1241 goto out_class;
1237 } 1242 }
1238 1243
1239 err = misc_register(&ubi_ctrl_cdev); 1244 err = misc_register(&ubi_ctrl_cdev);
1240 if (err) { 1245 if (err) {
1241 ubi_err("cannot register device"); 1246 pr_err("UBI error: cannot register device");
1242 goto out_version; 1247 goto out_version;
1243 } 1248 }
1244 1249
@@ -1265,7 +1270,8 @@ static int __init ubi_init(void)
1265 mtd = open_mtd_device(p->name); 1270 mtd = open_mtd_device(p->name);
1266 if (IS_ERR(mtd)) { 1271 if (IS_ERR(mtd)) {
1267 err = PTR_ERR(mtd); 1272 err = PTR_ERR(mtd);
1268 ubi_err("cannot open mtd %s, error %d", p->name, err); 1273 pr_err("UBI error: cannot open mtd %s, error %d",
1274 p->name, err);
1269 /* See comment below re-ubi_is_module(). */ 1275 /* See comment below re-ubi_is_module(). */
1270 if (ubi_is_module()) 1276 if (ubi_is_module())
1271 goto out_detach; 1277 goto out_detach;
@@ -1277,7 +1283,8 @@ static int __init ubi_init(void)
1277 p->vid_hdr_offs, p->max_beb_per1024); 1283 p->vid_hdr_offs, p->max_beb_per1024);
1278 mutex_unlock(&ubi_devices_mutex); 1284 mutex_unlock(&ubi_devices_mutex);
1279 if (err < 0) { 1285 if (err < 0) {
1280 ubi_err("cannot attach mtd%d", mtd->index); 1286 pr_err("UBI error: cannot attach mtd%d",
1287 mtd->index);
1281 put_mtd_device(mtd); 1288 put_mtd_device(mtd);
1282 1289
1283 /* 1290 /*
@@ -1300,7 +1307,7 @@ static int __init ubi_init(void)
1300 1307
1301 err = ubiblock_init(); 1308 err = ubiblock_init();
1302 if (err) { 1309 if (err) {
1303 ubi_err("block: cannot initialize, error %d", err); 1310 pr_err("UBI error: block: cannot initialize, error %d", err);
1304 1311
1305 /* See comment above re-ubi_is_module(). */ 1312 /* See comment above re-ubi_is_module(). */
1306 if (ubi_is_module()) 1313 if (ubi_is_module())
@@ -1326,7 +1333,7 @@ out_version:
1326out_class: 1333out_class:
1327 class_destroy(ubi_class); 1334 class_destroy(ubi_class);
1328out: 1335out:
1329 ubi_err("cannot initialize UBI, error %d", err); 1336 pr_err("UBI error: cannot initialize UBI, error %d", err);
1330 return err; 1337 return err;
1331} 1338}
1332late_initcall(ubi_init); 1339late_initcall(ubi_init);
@@ -1365,7 +1372,7 @@ static int __init bytes_str_to_int(const char *str)
1365 1372
1366 result = simple_strtoul(str, &endp, 0); 1373 result = simple_strtoul(str, &endp, 0);
1367 if (str == endp || result >= INT_MAX) { 1374 if (str == endp || result >= INT_MAX) {
1368 ubi_err("incorrect bytes count: \"%s\"\n", str); 1375 pr_err("UBI error: incorrect bytes count: \"%s\"\n", str);
1369 return -EINVAL; 1376 return -EINVAL;
1370 } 1377 }
1371 1378
@@ -1381,7 +1388,7 @@ static int __init bytes_str_to_int(const char *str)
1381 case '\0': 1388 case '\0':
1382 break; 1389 break;
1383 default: 1390 default:
1384 ubi_err("incorrect bytes count: \"%s\"\n", str); 1391 pr_err("UBI error: incorrect bytes count: \"%s\"\n", str);
1385 return -EINVAL; 1392 return -EINVAL;
1386 } 1393 }
1387 1394
@@ -1408,20 +1415,20 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1408 return -EINVAL; 1415 return -EINVAL;
1409 1416
1410 if (mtd_devs == UBI_MAX_DEVICES) { 1417 if (mtd_devs == UBI_MAX_DEVICES) {
1411 ubi_err("too many parameters, max. is %d\n", 1418 pr_err("UBI error: too many parameters, max. is %d\n",
1412 UBI_MAX_DEVICES); 1419 UBI_MAX_DEVICES);
1413 return -EINVAL; 1420 return -EINVAL;
1414 } 1421 }
1415 1422
1416 len = strnlen(val, MTD_PARAM_LEN_MAX); 1423 len = strnlen(val, MTD_PARAM_LEN_MAX);
1417 if (len == MTD_PARAM_LEN_MAX) { 1424 if (len == MTD_PARAM_LEN_MAX) {
1418 ubi_err("parameter \"%s\" is too long, max. is %d\n", 1425 pr_err("UBI error: parameter \"%s\" is too long, max. is %d\n",
1419 val, MTD_PARAM_LEN_MAX); 1426 val, MTD_PARAM_LEN_MAX);
1420 return -EINVAL; 1427 return -EINVAL;
1421 } 1428 }
1422 1429
1423 if (len == 0) { 1430 if (len == 0) {
1424 pr_warn("UBI warning: empty 'mtd=' parameter - ignored\n"); 1431 pr_err("UBI warning: empty 'mtd=' parameter - ignored\n");
1425 return 0; 1432 return 0;
1426 } 1433 }
1427 1434
@@ -1435,7 +1442,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1435 tokens[i] = strsep(&pbuf, ","); 1442 tokens[i] = strsep(&pbuf, ",");
1436 1443
1437 if (pbuf) { 1444 if (pbuf) {
1438 ubi_err("too many arguments at \"%s\"\n", val); 1445 pr_err("UBI error: too many arguments at \"%s\"\n", val);
1439 return -EINVAL; 1446 return -EINVAL;
1440 } 1447 }
1441 1448
@@ -1455,8 +1462,8 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1455 int err = kstrtoint(token, 10, &p->max_beb_per1024); 1462 int err = kstrtoint(token, 10, &p->max_beb_per1024);
1456 1463
1457 if (err) { 1464 if (err) {
1458 ubi_err("bad value for max_beb_per1024 parameter: %s", 1465 pr_err("UBI error: bad value for max_beb_per1024 parameter: %s",
1459 token); 1466 token);
1460 return -EINVAL; 1467 return -EINVAL;
1461 } 1468 }
1462 } 1469 }
@@ -1466,7 +1473,8 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1466 int err = kstrtoint(token, 10, &p->ubi_num); 1473 int err = kstrtoint(token, 10, &p->ubi_num);
1467 1474
1468 if (err) { 1475 if (err) {
1469 ubi_err("bad value for ubi_num parameter: %s", token); 1476 pr_err("UBI error: bad value for ubi_num parameter: %s",
1477 token);
1470 return -EINVAL; 1478 return -EINVAL;
1471 } 1479 }
1472 } else 1480 } else
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 59de69a24e40..3410ea8109f8 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -48,13 +48,14 @@
48 48
49/** 49/**
50 * get_exclusive - get exclusive access to an UBI volume. 50 * get_exclusive - get exclusive access to an UBI volume.
51 * @ubi: UBI device description object
51 * @desc: volume descriptor 52 * @desc: volume descriptor
52 * 53 *
53 * This function changes UBI volume open mode to "exclusive". Returns previous 54 * This function changes UBI volume open mode to "exclusive". Returns previous
54 * mode value (positive integer) in case of success and a negative error code 55 * mode value (positive integer) in case of success and a negative error code
55 * in case of failure. 56 * in case of failure.
56 */ 57 */
57static int get_exclusive(struct ubi_volume_desc *desc) 58static int get_exclusive(struct ubi_device *ubi, struct ubi_volume_desc *desc)
58{ 59{
59 int users, err; 60 int users, err;
60 struct ubi_volume *vol = desc->vol; 61 struct ubi_volume *vol = desc->vol;
@@ -63,7 +64,7 @@ static int get_exclusive(struct ubi_volume_desc *desc)
63 users = vol->readers + vol->writers + vol->exclusive; 64 users = vol->readers + vol->writers + vol->exclusive;
64 ubi_assert(users > 0); 65 ubi_assert(users > 0);
65 if (users > 1) { 66 if (users > 1) {
66 ubi_err("%d users for volume %d", users, vol->vol_id); 67 ubi_err(ubi, "%d users for volume %d", users, vol->vol_id);
67 err = -EBUSY; 68 err = -EBUSY;
68 } else { 69 } else {
69 vol->readers = vol->writers = 0; 70 vol->readers = vol->writers = 0;
@@ -134,7 +135,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
134 vol->ubi->ubi_num, vol->vol_id, desc->mode); 135 vol->ubi->ubi_num, vol->vol_id, desc->mode);
135 136
136 if (vol->updating) { 137 if (vol->updating) {
137 ubi_warn("update of volume %d not finished, volume is damaged", 138 ubi_warn(vol->ubi, "update of volume %d not finished, volume is damaged",
138 vol->vol_id); 139 vol->vol_id);
139 ubi_assert(!vol->changing_leb); 140 ubi_assert(!vol->changing_leb);
140 vol->updating = 0; 141 vol->updating = 0;
@@ -158,7 +159,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin)
158 159
159 if (vol->updating) { 160 if (vol->updating) {
160 /* Update is in progress, seeking is prohibited */ 161 /* Update is in progress, seeking is prohibited */
161 ubi_err("updating"); 162 ubi_err(vol->ubi, "updating");
162 return -EBUSY; 163 return -EBUSY;
163 } 164 }
164 165
@@ -193,11 +194,11 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
193 count, *offp, vol->vol_id); 194 count, *offp, vol->vol_id);
194 195
195 if (vol->updating) { 196 if (vol->updating) {
196 ubi_err("updating"); 197 ubi_err(vol->ubi, "updating");
197 return -EBUSY; 198 return -EBUSY;
198 } 199 }
199 if (vol->upd_marker) { 200 if (vol->upd_marker) {
200 ubi_err("damaged volume, update marker is set"); 201 ubi_err(vol->ubi, "damaged volume, update marker is set");
201 return -EBADF; 202 return -EBADF;
202 } 203 }
203 if (*offp == vol->used_bytes || count == 0) 204 if (*offp == vol->used_bytes || count == 0)
@@ -277,7 +278,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
277 278
278 lnum = div_u64_rem(*offp, vol->usable_leb_size, &off); 279 lnum = div_u64_rem(*offp, vol->usable_leb_size, &off);
279 if (off & (ubi->min_io_size - 1)) { 280 if (off & (ubi->min_io_size - 1)) {
280 ubi_err("unaligned position"); 281 ubi_err(ubi, "unaligned position");
281 return -EINVAL; 282 return -EINVAL;
282 } 283 }
283 284
@@ -286,7 +287,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
286 287
287 /* We can write only in fractions of the minimum I/O unit */ 288 /* We can write only in fractions of the minimum I/O unit */
288 if (count & (ubi->min_io_size - 1)) { 289 if (count & (ubi->min_io_size - 1)) {
289 ubi_err("unaligned write length"); 290 ubi_err(ubi, "unaligned write length");
290 return -EINVAL; 291 return -EINVAL;
291 } 292 }
292 293
@@ -348,7 +349,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
348 err = ubi_more_leb_change_data(ubi, vol, buf, count); 349 err = ubi_more_leb_change_data(ubi, vol, buf, count);
349 350
350 if (err < 0) { 351 if (err < 0) {
351 ubi_err("cannot accept more %zd bytes of data, error %d", 352 ubi_err(ubi, "cannot accept more %zd bytes of data, error %d",
352 count, err); 353 count, err);
353 return err; 354 return err;
354 } 355 }
@@ -370,7 +371,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
370 return err; 371 return err;
371 372
372 if (err) { 373 if (err) {
373 ubi_warn("volume %d on UBI device %d is corrupted", 374 ubi_warn(ubi, "volume %d on UBI device %d is corrupted",
374 vol->vol_id, ubi->ubi_num); 375 vol->vol_id, ubi->ubi_num);
375 vol->corrupted = 1; 376 vol->corrupted = 1;
376 } 377 }
@@ -420,7 +421,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
420 break; 421 break;
421 } 422 }
422 423
423 err = get_exclusive(desc); 424 err = get_exclusive(ubi, desc);
424 if (err < 0) 425 if (err < 0)
425 break; 426 break;
426 427
@@ -456,7 +457,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
456 req.bytes < 0 || req.lnum >= vol->usable_leb_size) 457 req.bytes < 0 || req.lnum >= vol->usable_leb_size)
457 break; 458 break;
458 459
459 err = get_exclusive(desc); 460 err = get_exclusive(ubi, desc);
460 if (err < 0) 461 if (err < 0)
461 break; 462 break;
462 463
@@ -642,7 +643,7 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
642 return 0; 643 return 0;
643 644
644bad: 645bad:
645 ubi_err("bad volume creation request"); 646 ubi_err(ubi, "bad volume creation request");
646 ubi_dump_mkvol_req(req); 647 ubi_dump_mkvol_req(req);
647 return err; 648 return err;
648} 649}
@@ -708,12 +709,12 @@ static int rename_volumes(struct ubi_device *ubi,
708 for (i = 0; i < req->count - 1; i++) { 709 for (i = 0; i < req->count - 1; i++) {
709 for (n = i + 1; n < req->count; n++) { 710 for (n = i + 1; n < req->count; n++) {
710 if (req->ents[i].vol_id == req->ents[n].vol_id) { 711 if (req->ents[i].vol_id == req->ents[n].vol_id) {
711 ubi_err("duplicated volume id %d", 712 ubi_err(ubi, "duplicated volume id %d",
712 req->ents[i].vol_id); 713 req->ents[i].vol_id);
713 return -EINVAL; 714 return -EINVAL;
714 } 715 }
715 if (!strcmp(req->ents[i].name, req->ents[n].name)) { 716 if (!strcmp(req->ents[i].name, req->ents[n].name)) {
716 ubi_err("duplicated volume name \"%s\"", 717 ubi_err(ubi, "duplicated volume name \"%s\"",
717 req->ents[i].name); 718 req->ents[i].name);
718 return -EINVAL; 719 return -EINVAL;
719 } 720 }
@@ -736,7 +737,8 @@ static int rename_volumes(struct ubi_device *ubi,
736 re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_READWRITE); 737 re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_READWRITE);
737 if (IS_ERR(re->desc)) { 738 if (IS_ERR(re->desc)) {
738 err = PTR_ERR(re->desc); 739 err = PTR_ERR(re->desc);
739 ubi_err("cannot open volume %d, error %d", vol_id, err); 740 ubi_err(ubi, "cannot open volume %d, error %d",
741 vol_id, err);
740 kfree(re); 742 kfree(re);
741 goto out_free; 743 goto out_free;
742 } 744 }
@@ -795,7 +797,7 @@ static int rename_volumes(struct ubi_device *ubi,
795 continue; 797 continue;
796 798
797 /* The volume exists but busy, or an error occurred */ 799 /* The volume exists but busy, or an error occurred */
798 ubi_err("cannot open volume \"%s\", error %d", 800 ubi_err(ubi, "cannot open volume \"%s\", error %d",
799 re->new_name, err); 801 re->new_name, err);
800 goto out_free; 802 goto out_free;
801 } 803 }
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 63cb1d7236ce..7335c9ff9d99 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -43,12 +43,12 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len)
43 return; 43 return;
44 err = mtd_read(ubi->mtd, addr, len, &read, buf); 44 err = mtd_read(ubi->mtd, addr, len, &read, buf);
45 if (err && err != -EUCLEAN) { 45 if (err && err != -EUCLEAN) {
46 ubi_err("error %d while reading %d bytes from PEB %d:%d, read %zd bytes", 46 ubi_err(ubi, "err %d while reading %d bytes from PEB %d:%d, read %zd bytes",
47 err, len, pnum, offset, read); 47 err, len, pnum, offset, read);
48 goto out; 48 goto out;
49 } 49 }
50 50
51 ubi_msg("dumping %d bytes of data from PEB %d, offset %d", 51 ubi_msg(ubi, "dumping %d bytes of data from PEB %d, offset %d",
52 len, pnum, offset); 52 len, pnum, offset);
53 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); 53 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1);
54out: 54out:
@@ -238,8 +238,8 @@ int ubi_debugfs_init(void)
238 if (IS_ERR_OR_NULL(dfs_rootdir)) { 238 if (IS_ERR_OR_NULL(dfs_rootdir)) {
239 int err = dfs_rootdir ? -ENODEV : PTR_ERR(dfs_rootdir); 239 int err = dfs_rootdir ? -ENODEV : PTR_ERR(dfs_rootdir);
240 240
241 ubi_err("cannot create \"ubi\" debugfs directory, error %d\n", 241 pr_err("UBI error: cannot create \"ubi\" debugfs directory, error %d\n",
242 err); 242 err);
243 return err; 243 return err;
244 } 244 }
245 245
@@ -433,7 +433,7 @@ out_remove:
433 debugfs_remove_recursive(d->dfs_dir); 433 debugfs_remove_recursive(d->dfs_dir);
434out: 434out:
435 err = dent ? PTR_ERR(dent) : -ENODEV; 435 err = dent ? PTR_ERR(dent) : -ENODEV;
436 ubi_err("cannot create \"%s\" debugfs file or directory, error %d\n", 436 ubi_err(ubi, "cannot create \"%s\" debugfs file or directory, error %d\n",
437 fname, err); 437 fname, err);
438 return err; 438 return err;
439} 439}
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 2402d3b50171..a40020cf0923 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -422,7 +422,7 @@ retry:
422 */ 422 */
423 if (err == UBI_IO_BAD_HDR_EBADMSG || 423 if (err == UBI_IO_BAD_HDR_EBADMSG ||
424 err == UBI_IO_BAD_HDR) { 424 err == UBI_IO_BAD_HDR) {
425 ubi_warn("corrupted VID header at PEB %d, LEB %d:%d", 425 ubi_warn(ubi, "corrupted VID header at PEB %d, LEB %d:%d",
426 pnum, vol_id, lnum); 426 pnum, vol_id, lnum);
427 err = -EBADMSG; 427 err = -EBADMSG;
428 } else 428 } else
@@ -448,7 +448,7 @@ retry:
448 goto out_unlock; 448 goto out_unlock;
449 scrub = 1; 449 scrub = 1;
450 if (!check) { 450 if (!check) {
451 ubi_msg("force data checking"); 451 ubi_msg(ubi, "force data checking");
452 check = 1; 452 check = 1;
453 goto retry; 453 goto retry;
454 } 454 }
@@ -459,7 +459,7 @@ retry:
459 if (check) { 459 if (check) {
460 uint32_t crc1 = crc32(UBI_CRC32_INIT, buf, len); 460 uint32_t crc1 = crc32(UBI_CRC32_INIT, buf, len);
461 if (crc1 != crc) { 461 if (crc1 != crc) {
462 ubi_warn("CRC error: calculated %#08x, must be %#08x", 462 ubi_warn(ubi, "CRC error: calculated %#08x, must be %#08x",
463 crc1, crc); 463 crc1, crc);
464 err = -EBADMSG; 464 err = -EBADMSG;
465 goto out_unlock; 465 goto out_unlock;
@@ -513,7 +513,8 @@ retry:
513 return new_pnum; 513 return new_pnum;
514 } 514 }
515 515
516 ubi_msg("recover PEB %d, move data to PEB %d", pnum, new_pnum); 516 ubi_msg(ubi, "recover PEB %d, move data to PEB %d",
517 pnum, new_pnum);
517 518
518 err = ubi_io_read_vid_hdr(ubi, pnum, vid_hdr, 1); 519 err = ubi_io_read_vid_hdr(ubi, pnum, vid_hdr, 1);
519 if (err && err != UBI_IO_BITFLIPS) { 520 if (err && err != UBI_IO_BITFLIPS) {
@@ -554,7 +555,7 @@ retry:
554 up_read(&ubi->fm_sem); 555 up_read(&ubi->fm_sem);
555 ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1); 556 ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
556 557
557 ubi_msg("data was successfully recovered"); 558 ubi_msg(ubi, "data was successfully recovered");
558 return 0; 559 return 0;
559 560
560out_unlock: 561out_unlock:
@@ -569,13 +570,13 @@ write_error:
569 * Bad luck? This physical eraseblock is bad too? Crud. Let's try to 570 * Bad luck? This physical eraseblock is bad too? Crud. Let's try to
570 * get another one. 571 * get another one.
571 */ 572 */
572 ubi_warn("failed to write to PEB %d", new_pnum); 573 ubi_warn(ubi, "failed to write to PEB %d", new_pnum);
573 ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1); 574 ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1);
574 if (++tries > UBI_IO_RETRIES) { 575 if (++tries > UBI_IO_RETRIES) {
575 ubi_free_vid_hdr(ubi, vid_hdr); 576 ubi_free_vid_hdr(ubi, vid_hdr);
576 return err; 577 return err;
577 } 578 }
578 ubi_msg("try again"); 579 ubi_msg(ubi, "try again");
579 goto retry; 580 goto retry;
580} 581}
581 582
@@ -613,7 +614,7 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
613 614
614 err = ubi_io_write_data(ubi, buf, pnum, offset, len); 615 err = ubi_io_write_data(ubi, buf, pnum, offset, len);
615 if (err) { 616 if (err) {
616 ubi_warn("failed to write data to PEB %d", pnum); 617 ubi_warn(ubi, "failed to write data to PEB %d", pnum);
617 if (err == -EIO && ubi->bad_allowed) 618 if (err == -EIO && ubi->bad_allowed)
618 err = recover_peb(ubi, pnum, vol_id, lnum, buf, 619 err = recover_peb(ubi, pnum, vol_id, lnum, buf,
619 offset, len); 620 offset, len);
@@ -654,7 +655,7 @@ retry:
654 655
655 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr); 656 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr);
656 if (err) { 657 if (err) {
657 ubi_warn("failed to write VID header to LEB %d:%d, PEB %d", 658 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
658 vol_id, lnum, pnum); 659 vol_id, lnum, pnum);
659 goto write_error; 660 goto write_error;
660 } 661 }
@@ -662,7 +663,7 @@ retry:
662 if (len) { 663 if (len) {
663 err = ubi_io_write_data(ubi, buf, pnum, offset, len); 664 err = ubi_io_write_data(ubi, buf, pnum, offset, len);
664 if (err) { 665 if (err) {
665 ubi_warn("failed to write %d bytes at offset %d of LEB %d:%d, PEB %d", 666 ubi_warn(ubi, "failed to write %d bytes at offset %d of LEB %d:%d, PEB %d",
666 len, offset, vol_id, lnum, pnum); 667 len, offset, vol_id, lnum, pnum);
667 goto write_error; 668 goto write_error;
668 } 669 }
@@ -698,7 +699,7 @@ write_error:
698 } 699 }
699 700
700 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); 701 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
701 ubi_msg("try another PEB"); 702 ubi_msg(ubi, "try another PEB");
702 goto retry; 703 goto retry;
703} 704}
704 705
@@ -775,14 +776,14 @@ retry:
775 776
776 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr); 777 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr);
777 if (err) { 778 if (err) {
778 ubi_warn("failed to write VID header to LEB %d:%d, PEB %d", 779 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
779 vol_id, lnum, pnum); 780 vol_id, lnum, pnum);
780 goto write_error; 781 goto write_error;
781 } 782 }
782 783
783 err = ubi_io_write_data(ubi, buf, pnum, 0, len); 784 err = ubi_io_write_data(ubi, buf, pnum, 0, len);
784 if (err) { 785 if (err) {
785 ubi_warn("failed to write %d bytes of data to PEB %d", 786 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d",
786 len, pnum); 787 len, pnum);
787 goto write_error; 788 goto write_error;
788 } 789 }
@@ -818,7 +819,7 @@ write_error:
818 } 819 }
819 820
820 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); 821 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
821 ubi_msg("try another PEB"); 822 ubi_msg(ubi, "try another PEB");
822 goto retry; 823 goto retry;
823} 824}
824 825
@@ -893,14 +894,14 @@ retry:
893 894
894 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr); 895 err = ubi_io_write_vid_hdr(ubi, pnum, vid_hdr);
895 if (err) { 896 if (err) {
896 ubi_warn("failed to write VID header to LEB %d:%d, PEB %d", 897 ubi_warn(ubi, "failed to write VID header to LEB %d:%d, PEB %d",
897 vol_id, lnum, pnum); 898 vol_id, lnum, pnum);
898 goto write_error; 899 goto write_error;
899 } 900 }
900 901
901 err = ubi_io_write_data(ubi, buf, pnum, 0, len); 902 err = ubi_io_write_data(ubi, buf, pnum, 0, len);
902 if (err) { 903 if (err) {
903 ubi_warn("failed to write %d bytes of data to PEB %d", 904 ubi_warn(ubi, "failed to write %d bytes of data to PEB %d",
904 len, pnum); 905 len, pnum);
905 goto write_error; 906 goto write_error;
906 } 907 }
@@ -940,7 +941,7 @@ write_error:
940 } 941 }
941 942
942 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); 943 vid_hdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
943 ubi_msg("try another PEB"); 944 ubi_msg(ubi, "try another PEB");
944 goto retry; 945 goto retry;
945} 946}
946 947
@@ -1063,7 +1064,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
1063 dbg_wl("read %d bytes of data", aldata_size); 1064 dbg_wl("read %d bytes of data", aldata_size);
1064 err = ubi_io_read_data(ubi, ubi->peb_buf, from, 0, aldata_size); 1065 err = ubi_io_read_data(ubi, ubi->peb_buf, from, 0, aldata_size);
1065 if (err && err != UBI_IO_BITFLIPS) { 1066 if (err && err != UBI_IO_BITFLIPS) {
1066 ubi_warn("error %d while reading data from PEB %d", 1067 ubi_warn(ubi, "error %d while reading data from PEB %d",
1067 err, from); 1068 err, from);
1068 err = MOVE_SOURCE_RD_ERR; 1069 err = MOVE_SOURCE_RD_ERR;
1069 goto out_unlock_buf; 1070 goto out_unlock_buf;
@@ -1113,7 +1114,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
1113 err = ubi_io_read_vid_hdr(ubi, to, vid_hdr, 1); 1114 err = ubi_io_read_vid_hdr(ubi, to, vid_hdr, 1);
1114 if (err) { 1115 if (err) {
1115 if (err != UBI_IO_BITFLIPS) { 1116 if (err != UBI_IO_BITFLIPS) {
1116 ubi_warn("error %d while reading VID header back from PEB %d", 1117 ubi_warn(ubi, "error %d while reading VID header back from PEB %d",
1117 err, to); 1118 err, to);
1118 if (is_error_sane(err)) 1119 if (is_error_sane(err))
1119 err = MOVE_TARGET_RD_ERR; 1120 err = MOVE_TARGET_RD_ERR;
@@ -1140,7 +1141,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
1140 err = ubi_io_read_data(ubi, ubi->peb_buf, to, 0, aldata_size); 1141 err = ubi_io_read_data(ubi, ubi->peb_buf, to, 0, aldata_size);
1141 if (err) { 1142 if (err) {
1142 if (err != UBI_IO_BITFLIPS) { 1143 if (err != UBI_IO_BITFLIPS) {
1143 ubi_warn("error %d while reading data back from PEB %d", 1144 ubi_warn(ubi, "error %d while reading data back from PEB %d",
1144 err, to); 1145 err, to);
1145 if (is_error_sane(err)) 1146 if (is_error_sane(err))
1146 err = MOVE_TARGET_RD_ERR; 1147 err = MOVE_TARGET_RD_ERR;
@@ -1152,7 +1153,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
1152 cond_resched(); 1153 cond_resched();
1153 1154
1154 if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size)) { 1155 if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size)) {
1155 ubi_warn("read data back from PEB %d and it is different", 1156 ubi_warn(ubi, "read data back from PEB %d and it is different",
1156 to); 1157 to);
1157 err = -EINVAL; 1158 err = -EINVAL;
1158 goto out_unlock_buf; 1159 goto out_unlock_buf;
@@ -1205,10 +1206,10 @@ static void print_rsvd_warning(struct ubi_device *ubi,
1205 return; 1206 return;
1206 } 1207 }
1207 1208
1208 ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d, need %d", 1209 ubi_warn(ubi, "cannot reserve enough PEBs for bad PEB handling, reserved %d, need %d",
1209 ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); 1210 ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
1210 if (ubi->corr_peb_count) 1211 if (ubi->corr_peb_count)
1211 ubi_warn("%d PEBs are corrupted and not used", 1212 ubi_warn(ubi, "%d PEBs are corrupted and not used",
1212 ubi->corr_peb_count); 1213 ubi->corr_peb_count);
1213} 1214}
1214 1215
@@ -1286,7 +1287,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
1286 fm_eba[i][j] == UBI_LEB_UNMAPPED) 1287 fm_eba[i][j] == UBI_LEB_UNMAPPED)
1287 continue; 1288 continue;
1288 1289
1289 ubi_err("LEB:%i:%i is PEB:%i instead of %i!", 1290 ubi_err(ubi, "LEB:%i:%i is PEB:%i instead of %i!",
1290 vol->vol_id, i, fm_eba[i][j], 1291 vol->vol_id, i, fm_eba[i][j],
1291 scan_eba[i][j]); 1292 scan_eba[i][j]);
1292 ubi_assert(0); 1293 ubi_assert(0);
@@ -1366,10 +1367,10 @@ int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1366 } 1367 }
1367 1368
1368 if (ubi->avail_pebs < EBA_RESERVED_PEBS) { 1369 if (ubi->avail_pebs < EBA_RESERVED_PEBS) {
1369 ubi_err("no enough physical eraseblocks (%d, need %d)", 1370 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)",
1370 ubi->avail_pebs, EBA_RESERVED_PEBS); 1371 ubi->avail_pebs, EBA_RESERVED_PEBS);
1371 if (ubi->corr_peb_count) 1372 if (ubi->corr_peb_count)
1372 ubi_err("%d PEBs are corrupted and not used", 1373 ubi_err(ubi, "%d PEBs are corrupted and not used",
1373 ubi->corr_peb_count); 1374 ubi->corr_peb_count);
1374 err = -ENOSPC; 1375 err = -ENOSPC;
1375 goto out_free; 1376 goto out_free;
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index cfd5b5e90156..b56672bf3294 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -330,7 +330,7 @@ static int process_pool_aeb(struct ubi_device *ubi, struct ubi_attach_info *ai,
330 if (found) 330 if (found)
331 av = tmp_av; 331 av = tmp_av;
332 else { 332 else {
333 ubi_err("orphaned volume in fastmap pool!"); 333 ubi_err(ubi, "orphaned volume in fastmap pool!");
334 kmem_cache_free(ai->aeb_slab_cache, new_aeb); 334 kmem_cache_free(ai->aeb_slab_cache, new_aeb);
335 return UBI_BAD_FASTMAP; 335 return UBI_BAD_FASTMAP;
336 } 336 }
@@ -414,14 +414,14 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
414 pnum = be32_to_cpu(pebs[i]); 414 pnum = be32_to_cpu(pebs[i]);
415 415
416 if (ubi_io_is_bad(ubi, pnum)) { 416 if (ubi_io_is_bad(ubi, pnum)) {
417 ubi_err("bad PEB in fastmap pool!"); 417 ubi_err(ubi, "bad PEB in fastmap pool!");
418 ret = UBI_BAD_FASTMAP; 418 ret = UBI_BAD_FASTMAP;
419 goto out; 419 goto out;
420 } 420 }
421 421
422 err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); 422 err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
423 if (err && err != UBI_IO_BITFLIPS) { 423 if (err && err != UBI_IO_BITFLIPS) {
424 ubi_err("unable to read EC header! PEB:%i err:%i", 424 ubi_err(ubi, "unable to read EC header! PEB:%i err:%i",
425 pnum, err); 425 pnum, err);
426 ret = err > 0 ? UBI_BAD_FASTMAP : err; 426 ret = err > 0 ? UBI_BAD_FASTMAP : err;
427 goto out; 427 goto out;
@@ -435,7 +435,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
435 image_seq = be32_to_cpu(ech->image_seq); 435 image_seq = be32_to_cpu(ech->image_seq);
436 436
437 if (image_seq && (image_seq != ubi->image_seq)) { 437 if (image_seq && (image_seq != ubi->image_seq)) {
438 ubi_err("bad image seq: 0x%x, expected: 0x%x", 438 ubi_err(ubi, "bad image seq: 0x%x, expected: 0x%x",
439 be32_to_cpu(ech->image_seq), ubi->image_seq); 439 be32_to_cpu(ech->image_seq), ubi->image_seq);
440 ret = UBI_BAD_FASTMAP; 440 ret = UBI_BAD_FASTMAP;
441 goto out; 441 goto out;
@@ -493,7 +493,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
493 } 493 }
494 } else { 494 } else {
495 /* We are paranoid and fall back to scanning mode */ 495 /* We are paranoid and fall back to scanning mode */
496 ubi_err("fastmap pool PEBs contains damaged PEBs!"); 496 ubi_err(ubi, "fastmap pool PEBs contains damaged PEBs!");
497 ret = err > 0 ? UBI_BAD_FASTMAP : err; 497 ret = err > 0 ? UBI_BAD_FASTMAP : err;
498 goto out; 498 goto out;
499 } 499 }
@@ -588,7 +588,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
588 goto fail_bad; 588 goto fail_bad;
589 589
590 if (be32_to_cpu(fmhdr->magic) != UBI_FM_HDR_MAGIC) { 590 if (be32_to_cpu(fmhdr->magic) != UBI_FM_HDR_MAGIC) {
591 ubi_err("bad fastmap header magic: 0x%x, expected: 0x%x", 591 ubi_err(ubi, "bad fastmap header magic: 0x%x, expected: 0x%x",
592 be32_to_cpu(fmhdr->magic), UBI_FM_HDR_MAGIC); 592 be32_to_cpu(fmhdr->magic), UBI_FM_HDR_MAGIC);
593 goto fail_bad; 593 goto fail_bad;
594 } 594 }
@@ -598,7 +598,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
598 if (fm_pos >= fm_size) 598 if (fm_pos >= fm_size)
599 goto fail_bad; 599 goto fail_bad;
600 if (be32_to_cpu(fmpl1->magic) != UBI_FM_POOL_MAGIC) { 600 if (be32_to_cpu(fmpl1->magic) != UBI_FM_POOL_MAGIC) {
601 ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x", 601 ubi_err(ubi, "bad fastmap pool magic: 0x%x, expected: 0x%x",
602 be32_to_cpu(fmpl1->magic), UBI_FM_POOL_MAGIC); 602 be32_to_cpu(fmpl1->magic), UBI_FM_POOL_MAGIC);
603 goto fail_bad; 603 goto fail_bad;
604 } 604 }
@@ -608,7 +608,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
608 if (fm_pos >= fm_size) 608 if (fm_pos >= fm_size)
609 goto fail_bad; 609 goto fail_bad;
610 if (be32_to_cpu(fmpl2->magic) != UBI_FM_POOL_MAGIC) { 610 if (be32_to_cpu(fmpl2->magic) != UBI_FM_POOL_MAGIC) {
611 ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x", 611 ubi_err(ubi, "bad fastmap pool magic: 0x%x, expected: 0x%x",
612 be32_to_cpu(fmpl2->magic), UBI_FM_POOL_MAGIC); 612 be32_to_cpu(fmpl2->magic), UBI_FM_POOL_MAGIC);
613 goto fail_bad; 613 goto fail_bad;
614 } 614 }
@@ -619,25 +619,26 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
619 fm->max_wl_pool_size = be16_to_cpu(fmpl2->max_size); 619 fm->max_wl_pool_size = be16_to_cpu(fmpl2->max_size);
620 620
621 if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) { 621 if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) {
622 ubi_err("bad pool size: %i", pool_size); 622 ubi_err(ubi, "bad pool size: %i", pool_size);
623 goto fail_bad; 623 goto fail_bad;
624 } 624 }
625 625
626 if (wl_pool_size > UBI_FM_MAX_POOL_SIZE || wl_pool_size < 0) { 626 if (wl_pool_size > UBI_FM_MAX_POOL_SIZE || wl_pool_size < 0) {
627 ubi_err("bad WL pool size: %i", wl_pool_size); 627 ubi_err(ubi, "bad WL pool size: %i", wl_pool_size);
628 goto fail_bad; 628 goto fail_bad;
629 } 629 }
630 630
631 631
632 if (fm->max_pool_size > UBI_FM_MAX_POOL_SIZE || 632 if (fm->max_pool_size > UBI_FM_MAX_POOL_SIZE ||
633 fm->max_pool_size < 0) { 633 fm->max_pool_size < 0) {
634 ubi_err("bad maximal pool size: %i", fm->max_pool_size); 634 ubi_err(ubi, "bad maximal pool size: %i", fm->max_pool_size);
635 goto fail_bad; 635 goto fail_bad;
636 } 636 }
637 637
638 if (fm->max_wl_pool_size > UBI_FM_MAX_POOL_SIZE || 638 if (fm->max_wl_pool_size > UBI_FM_MAX_POOL_SIZE ||
639 fm->max_wl_pool_size < 0) { 639 fm->max_wl_pool_size < 0) {
640 ubi_err("bad maximal WL pool size: %i", fm->max_wl_pool_size); 640 ubi_err(ubi, "bad maximal WL pool size: %i",
641 fm->max_wl_pool_size);
641 goto fail_bad; 642 goto fail_bad;
642 } 643 }
643 644
@@ -696,8 +697,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
696 goto fail_bad; 697 goto fail_bad;
697 698
698 if (be32_to_cpu(fmvhdr->magic) != UBI_FM_VHDR_MAGIC) { 699 if (be32_to_cpu(fmvhdr->magic) != UBI_FM_VHDR_MAGIC) {
699 ubi_err("bad fastmap vol header magic: 0x%x, " \ 700 ubi_err(ubi, "bad fastmap vol header magic: 0x%x, expected: 0x%x",
700 "expected: 0x%x",
701 be32_to_cpu(fmvhdr->magic), UBI_FM_VHDR_MAGIC); 701 be32_to_cpu(fmvhdr->magic), UBI_FM_VHDR_MAGIC);
702 goto fail_bad; 702 goto fail_bad;
703 } 703 }
@@ -722,8 +722,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
722 goto fail_bad; 722 goto fail_bad;
723 723
724 if (be32_to_cpu(fm_eba->magic) != UBI_FM_EBA_MAGIC) { 724 if (be32_to_cpu(fm_eba->magic) != UBI_FM_EBA_MAGIC) {
725 ubi_err("bad fastmap EBA header magic: 0x%x, " \ 725 ubi_err(ubi, "bad fastmap EBA header magic: 0x%x, expected: 0x%x",
726 "expected: 0x%x",
727 be32_to_cpu(fm_eba->magic), UBI_FM_EBA_MAGIC); 726 be32_to_cpu(fm_eba->magic), UBI_FM_EBA_MAGIC);
728 goto fail_bad; 727 goto fail_bad;
729 } 728 }
@@ -788,7 +787,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
788 int err; 787 int err;
789 788
790 if (ubi_io_is_bad(ubi, tmp_aeb->pnum)) { 789 if (ubi_io_is_bad(ubi, tmp_aeb->pnum)) {
791 ubi_err("bad PEB in fastmap EBA orphan list"); 790 ubi_err(ubi, "bad PEB in fastmap EBA orphan list");
792 ret = UBI_BAD_FASTMAP; 791 ret = UBI_BAD_FASTMAP;
793 kfree(ech); 792 kfree(ech);
794 goto fail; 793 goto fail;
@@ -796,8 +795,8 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
796 795
797 err = ubi_io_read_ec_hdr(ubi, tmp_aeb->pnum, ech, 0); 796 err = ubi_io_read_ec_hdr(ubi, tmp_aeb->pnum, ech, 0);
798 if (err && err != UBI_IO_BITFLIPS) { 797 if (err && err != UBI_IO_BITFLIPS) {
799 ubi_err("unable to read EC header! PEB:%i " \ 798 ubi_err(ubi, "unable to read EC header! PEB:%i err:%i",
800 "err:%i", tmp_aeb->pnum, err); 799 tmp_aeb->pnum, err);
801 ret = err > 0 ? UBI_BAD_FASTMAP : err; 800 ret = err > 0 ? UBI_BAD_FASTMAP : err;
802 kfree(ech); 801 kfree(ech);
803 802
@@ -908,14 +907,14 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
908 fm->to_be_tortured[0] = 1; 907 fm->to_be_tortured[0] = 1;
909 908
910 if (be32_to_cpu(fmsb->magic) != UBI_FM_SB_MAGIC) { 909 if (be32_to_cpu(fmsb->magic) != UBI_FM_SB_MAGIC) {
911 ubi_err("bad super block magic: 0x%x, expected: 0x%x", 910 ubi_err(ubi, "bad super block magic: 0x%x, expected: 0x%x",
912 be32_to_cpu(fmsb->magic), UBI_FM_SB_MAGIC); 911 be32_to_cpu(fmsb->magic), UBI_FM_SB_MAGIC);
913 ret = UBI_BAD_FASTMAP; 912 ret = UBI_BAD_FASTMAP;
914 goto free_fm_sb; 913 goto free_fm_sb;
915 } 914 }
916 915
917 if (fmsb->version != UBI_FM_FMT_VERSION) { 916 if (fmsb->version != UBI_FM_FMT_VERSION) {
918 ubi_err("bad fastmap version: %i, expected: %i", 917 ubi_err(ubi, "bad fastmap version: %i, expected: %i",
919 fmsb->version, UBI_FM_FMT_VERSION); 918 fmsb->version, UBI_FM_FMT_VERSION);
920 ret = UBI_BAD_FASTMAP; 919 ret = UBI_BAD_FASTMAP;
921 goto free_fm_sb; 920 goto free_fm_sb;
@@ -923,15 +922,16 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
923 922
924 used_blocks = be32_to_cpu(fmsb->used_blocks); 923 used_blocks = be32_to_cpu(fmsb->used_blocks);
925 if (used_blocks > UBI_FM_MAX_BLOCKS || used_blocks < 1) { 924 if (used_blocks > UBI_FM_MAX_BLOCKS || used_blocks < 1) {
926 ubi_err("number of fastmap blocks is invalid: %i", used_blocks); 925 ubi_err(ubi, "number of fastmap blocks is invalid: %i",
926 used_blocks);
927 ret = UBI_BAD_FASTMAP; 927 ret = UBI_BAD_FASTMAP;
928 goto free_fm_sb; 928 goto free_fm_sb;
929 } 929 }
930 930
931 fm_size = ubi->leb_size * used_blocks; 931 fm_size = ubi->leb_size * used_blocks;
932 if (fm_size != ubi->fm_size) { 932 if (fm_size != ubi->fm_size) {
933 ubi_err("bad fastmap size: %zi, expected: %zi", fm_size, 933 ubi_err(ubi, "bad fastmap size: %zi, expected: %zi",
934 ubi->fm_size); 934 fm_size, ubi->fm_size);
935 ret = UBI_BAD_FASTMAP; 935 ret = UBI_BAD_FASTMAP;
936 goto free_fm_sb; 936 goto free_fm_sb;
937 } 937 }
@@ -960,7 +960,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
960 960
961 ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); 961 ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
962 if (ret && ret != UBI_IO_BITFLIPS) { 962 if (ret && ret != UBI_IO_BITFLIPS) {
963 ubi_err("unable to read fastmap block# %i EC (PEB: %i)", 963 ubi_err(ubi, "unable to read fastmap block# %i EC (PEB: %i)",
964 i, pnum); 964 i, pnum);
965 if (ret > 0) 965 if (ret > 0)
966 ret = UBI_BAD_FASTMAP; 966 ret = UBI_BAD_FASTMAP;
@@ -977,7 +977,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
977 * we shouldn't fail if image_seq == 0. 977 * we shouldn't fail if image_seq == 0.
978 */ 978 */
979 if (image_seq && (image_seq != ubi->image_seq)) { 979 if (image_seq && (image_seq != ubi->image_seq)) {
980 ubi_err("wrong image seq:%d instead of %d", 980 ubi_err(ubi, "wrong image seq:%d instead of %d",
981 be32_to_cpu(ech->image_seq), ubi->image_seq); 981 be32_to_cpu(ech->image_seq), ubi->image_seq);
982 ret = UBI_BAD_FASTMAP; 982 ret = UBI_BAD_FASTMAP;
983 goto free_hdr; 983 goto free_hdr;
@@ -985,15 +985,14 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
985 985
986 ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); 986 ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
987 if (ret && ret != UBI_IO_BITFLIPS) { 987 if (ret && ret != UBI_IO_BITFLIPS) {
988 ubi_err("unable to read fastmap block# %i (PEB: %i)", 988 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i)",
989 i, pnum); 989 i, pnum);
990 goto free_hdr; 990 goto free_hdr;
991 } 991 }
992 992
993 if (i == 0) { 993 if (i == 0) {
994 if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) { 994 if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) {
995 ubi_err("bad fastmap anchor vol_id: 0x%x," \ 995 ubi_err(ubi, "bad fastmap anchor vol_id: 0x%x, expected: 0x%x",
996 " expected: 0x%x",
997 be32_to_cpu(vh->vol_id), 996 be32_to_cpu(vh->vol_id),
998 UBI_FM_SB_VOLUME_ID); 997 UBI_FM_SB_VOLUME_ID);
999 ret = UBI_BAD_FASTMAP; 998 ret = UBI_BAD_FASTMAP;
@@ -1001,8 +1000,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1001 } 1000 }
1002 } else { 1001 } else {
1003 if (be32_to_cpu(vh->vol_id) != UBI_FM_DATA_VOLUME_ID) { 1002 if (be32_to_cpu(vh->vol_id) != UBI_FM_DATA_VOLUME_ID) {
1004 ubi_err("bad fastmap data vol_id: 0x%x," \ 1003 ubi_err(ubi, "bad fastmap data vol_id: 0x%x, expected: 0x%x",
1005 " expected: 0x%x",
1006 be32_to_cpu(vh->vol_id), 1004 be32_to_cpu(vh->vol_id),
1007 UBI_FM_DATA_VOLUME_ID); 1005 UBI_FM_DATA_VOLUME_ID);
1008 ret = UBI_BAD_FASTMAP; 1006 ret = UBI_BAD_FASTMAP;
@@ -1016,7 +1014,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1016 ret = ubi_io_read(ubi, ubi->fm_buf + (ubi->leb_size * i), pnum, 1014 ret = ubi_io_read(ubi, ubi->fm_buf + (ubi->leb_size * i), pnum,
1017 ubi->leb_start, ubi->leb_size); 1015 ubi->leb_start, ubi->leb_size);
1018 if (ret && ret != UBI_IO_BITFLIPS) { 1016 if (ret && ret != UBI_IO_BITFLIPS) {
1019 ubi_err("unable to read fastmap block# %i (PEB: %i, " \ 1017 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i, "
1020 "err: %i)", i, pnum, ret); 1018 "err: %i)", i, pnum, ret);
1021 goto free_hdr; 1019 goto free_hdr;
1022 } 1020 }
@@ -1030,8 +1028,9 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1030 fmsb2->data_crc = 0; 1028 fmsb2->data_crc = 0;
1031 crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size); 1029 crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size);
1032 if (crc != tmp_crc) { 1030 if (crc != tmp_crc) {
1033 ubi_err("fastmap data CRC is invalid"); 1031 ubi_err(ubi, "fastmap data CRC is invalid");
1034 ubi_err("CRC should be: 0x%x, calc: 0x%x", tmp_crc, crc); 1032 ubi_err(ubi, "CRC should be: 0x%x, calc: 0x%x",
1033 tmp_crc, crc);
1035 ret = UBI_BAD_FASTMAP; 1034 ret = UBI_BAD_FASTMAP;
1036 goto free_hdr; 1035 goto free_hdr;
1037 } 1036 }
@@ -1067,9 +1066,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1067 ubi->fm = fm; 1066 ubi->fm = fm;
1068 ubi->fm_pool.max_size = ubi->fm->max_pool_size; 1067 ubi->fm_pool.max_size = ubi->fm->max_pool_size;
1069 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size; 1068 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
1070 ubi_msg("attached by fastmap"); 1069 ubi_msg(ubi, "attached by fastmap");
1071 ubi_msg("fastmap pool size: %d", ubi->fm_pool.max_size); 1070 ubi_msg(ubi, "fastmap pool size: %d", ubi->fm_pool.max_size);
1072 ubi_msg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size); 1071 ubi_msg(ubi, "fastmap WL pool size: %d",
1072 ubi->fm_wl_pool.max_size);
1073 ubi->fm_disabled = 0; 1073 ubi->fm_disabled = 0;
1074 1074
1075 ubi_free_vid_hdr(ubi, vh); 1075 ubi_free_vid_hdr(ubi, vh);
@@ -1077,7 +1077,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
1077out: 1077out:
1078 mutex_unlock(&ubi->fm_mutex); 1078 mutex_unlock(&ubi->fm_mutex);
1079 if (ret == UBI_BAD_FASTMAP) 1079 if (ret == UBI_BAD_FASTMAP)
1080 ubi_err("Attach by fastmap failed, doing a full scan!"); 1080 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!");
1081 return ret; 1081 return ret;
1082 1082
1083free_hdr: 1083free_hdr:
@@ -1273,7 +1273,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1273 dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum); 1273 dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum);
1274 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avhdr); 1274 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avhdr);
1275 if (ret) { 1275 if (ret) {
1276 ubi_err("unable to write vid_hdr to fastmap SB!"); 1276 ubi_err(ubi, "unable to write vid_hdr to fastmap SB!");
1277 goto out_kfree; 1277 goto out_kfree;
1278 } 1278 }
1279 1279
@@ -1293,7 +1293,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1293 new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum)); 1293 new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum));
1294 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvhdr); 1294 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvhdr);
1295 if (ret) { 1295 if (ret) {
1296 ubi_err("unable to write vid_hdr to PEB %i!", 1296 ubi_err(ubi, "unable to write vid_hdr to PEB %i!",
1297 new_fm->e[i]->pnum); 1297 new_fm->e[i]->pnum);
1298 goto out_kfree; 1298 goto out_kfree;
1299 } 1299 }
@@ -1303,7 +1303,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
1303 ret = ubi_io_write(ubi, fm_raw + (i * ubi->leb_size), 1303 ret = ubi_io_write(ubi, fm_raw + (i * ubi->leb_size),
1304 new_fm->e[i]->pnum, ubi->leb_start, ubi->leb_size); 1304 new_fm->e[i]->pnum, ubi->leb_start, ubi->leb_size);
1305 if (ret) { 1305 if (ret) {
1306 ubi_err("unable to write fastmap to PEB %i!", 1306 ubi_err(ubi, "unable to write fastmap to PEB %i!",
1307 new_fm->e[i]->pnum); 1307 new_fm->e[i]->pnum);
1308 goto out_kfree; 1308 goto out_kfree;
1309 } 1309 }
@@ -1450,7 +1450,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1450 ubi->fm = NULL; 1450 ubi->fm = NULL;
1451 1451
1452 if (new_fm->used_blocks > UBI_FM_MAX_BLOCKS) { 1452 if (new_fm->used_blocks > UBI_FM_MAX_BLOCKS) {
1453 ubi_err("fastmap too large"); 1453 ubi_err(ubi, "fastmap too large");
1454 ret = -ENOSPC; 1454 ret = -ENOSPC;
1455 goto err; 1455 goto err;
1456 } 1456 }
@@ -1462,7 +1462,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1462 1462
1463 if (!tmp_e && !old_fm) { 1463 if (!tmp_e && !old_fm) {
1464 int j; 1464 int j;
1465 ubi_err("could not get any free erase block"); 1465 ubi_err(ubi, "could not get any free erase block");
1466 1466
1467 for (j = 1; j < i; j++) 1467 for (j = 1; j < i; j++)
1468 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0); 1468 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0);
@@ -1478,7 +1478,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1478 ubi_wl_put_fm_peb(ubi, new_fm->e[j], 1478 ubi_wl_put_fm_peb(ubi, new_fm->e[j],
1479 j, 0); 1479 j, 0);
1480 1480
1481 ubi_err("could not erase old fastmap PEB"); 1481 ubi_err(ubi, "could not erase old fastmap PEB");
1482 goto err; 1482 goto err;
1483 } 1483 }
1484 1484
@@ -1504,7 +1504,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1504 ret = erase_block(ubi, old_fm->e[0]->pnum); 1504 ret = erase_block(ubi, old_fm->e[0]->pnum);
1505 if (ret < 0) { 1505 if (ret < 0) {
1506 int i; 1506 int i;
1507 ubi_err("could not erase old anchor PEB"); 1507 ubi_err(ubi, "could not erase old anchor PEB");
1508 1508
1509 for (i = 1; i < new_fm->used_blocks; i++) 1509 for (i = 1; i < new_fm->used_blocks; i++)
1510 ubi_wl_put_fm_peb(ubi, new_fm->e[i], 1510 ubi_wl_put_fm_peb(ubi, new_fm->e[i],
@@ -1525,7 +1525,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
1525 } else { 1525 } else {
1526 if (!tmp_e) { 1526 if (!tmp_e) {
1527 int i; 1527 int i;
1528 ubi_err("could not find any anchor PEB"); 1528 ubi_err(ubi, "could not find any anchor PEB");
1529 1529
1530 for (i = 1; i < new_fm->used_blocks; i++) 1530 for (i = 1; i < new_fm->used_blocks; i++)
1531 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0); 1531 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0);
@@ -1555,13 +1555,13 @@ out_unlock:
1555err: 1555err:
1556 kfree(new_fm); 1556 kfree(new_fm);
1557 1557
1558 ubi_warn("Unable to write new fastmap, err=%i", ret); 1558 ubi_warn(ubi, "Unable to write new fastmap, err=%i", ret);
1559 1559
1560 ret = 0; 1560 ret = 0;
1561 if (old_fm) { 1561 if (old_fm) {
1562 ret = invalidate_fastmap(ubi, old_fm); 1562 ret = invalidate_fastmap(ubi, old_fm);
1563 if (ret < 0) 1563 if (ret < 0)
1564 ubi_err("Unable to invalidiate current fastmap!"); 1564 ubi_err(ubi, "Unable to invalidiate current fastmap!");
1565 else if (ret) 1565 else if (ret)
1566 ret = 0; 1566 ret = 0;
1567 } 1567 }
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:
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 3aac1acceeb4..f3bab669f6bb 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -204,7 +204,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
204 return ERR_PTR(err); 204 return ERR_PTR(err);
205 } 205 }
206 if (err == 1) { 206 if (err == 1) {
207 ubi_warn("volume %d on UBI device %d is corrupted", 207 ubi_warn(ubi, "volume %d on UBI device %d is corrupted",
208 vol_id, ubi->ubi_num); 208 vol_id, ubi->ubi_num);
209 vol->corrupted = 1; 209 vol->corrupted = 1;
210 } 210 }
@@ -221,7 +221,7 @@ out_free:
221 kfree(desc); 221 kfree(desc);
222out_put_ubi: 222out_put_ubi:
223 ubi_put_device(ubi); 223 ubi_put_device(ubi);
224 ubi_err("cannot open device %d, volume %d, error %d", 224 ubi_err(ubi, "cannot open device %d, volume %d, error %d",
225 ubi_num, vol_id, err); 225 ubi_num, vol_id, err);
226 return ERR_PTR(err); 226 return ERR_PTR(err);
227} 227}
@@ -411,7 +411,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
411 411
412 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check); 412 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check);
413 if (err && mtd_is_eccerr(err) && vol->vol_type == UBI_STATIC_VOLUME) { 413 if (err && mtd_is_eccerr(err) && vol->vol_type == UBI_STATIC_VOLUME) {
414 ubi_warn("mark volume %d as corrupted", vol_id); 414 ubi_warn(ubi, "mark volume %d as corrupted", vol_id);
415 vol->corrupted = 1; 415 vol->corrupted = 1;
416 } 416 }
417 417
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index f913d701a5b3..dbda77e556cb 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -111,7 +111,7 @@ void ubi_update_reserved(struct ubi_device *ubi)
111 ubi->avail_pebs -= need; 111 ubi->avail_pebs -= need;
112 ubi->rsvd_pebs += need; 112 ubi->rsvd_pebs += need;
113 ubi->beb_rsvd_pebs += need; 113 ubi->beb_rsvd_pebs += need;
114 ubi_msg("reserved more %d PEBs for bad PEB handling", need); 114 ubi_msg(ubi, "reserved more %d PEBs for bad PEB handling", need);
115} 115}
116 116
117/** 117/**
@@ -128,7 +128,7 @@ void ubi_calculate_reserved(struct ubi_device *ubi)
128 ubi->beb_rsvd_level = ubi->bad_peb_limit - ubi->bad_peb_count; 128 ubi->beb_rsvd_level = ubi->bad_peb_limit - ubi->bad_peb_count;
129 if (ubi->beb_rsvd_level < 0) { 129 if (ubi->beb_rsvd_level < 0) {
130 ubi->beb_rsvd_level = 0; 130 ubi->beb_rsvd_level = 0;
131 ubi_warn("number of bad PEBs (%d) is above the expected limit (%d), not reserving any PEBs for bad PEB handling, will use available PEBs (if any)", 131 ubi_warn(ubi, "number of bad PEBs (%d) is above the expected limit (%d), not reserving any PEBs for bad PEB handling, will use available PEBs (if any)",
132 ubi->bad_peb_count, ubi->bad_peb_limit); 132 ubi->bad_peb_count, ubi->bad_peb_limit);
133 } 133 }
134} 134}
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 320fc38fa2a1..f80ffaba9058 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -50,13 +50,14 @@
50#define UBI_NAME_STR "ubi" 50#define UBI_NAME_STR "ubi"
51 51
52/* Normal UBI messages */ 52/* Normal UBI messages */
53#define ubi_msg(fmt, ...) pr_notice("UBI: " fmt "\n", ##__VA_ARGS__) 53#define ubi_msg(ubi, fmt, ...) pr_notice("UBI-%d: %s:" fmt "\n", \
54 ubi->ubi_num, __func__, ##__VA_ARGS__)
54/* UBI warning messages */ 55/* UBI warning messages */
55#define ubi_warn(fmt, ...) pr_warn("UBI warning: %s: " fmt "\n", \ 56#define ubi_warn(ubi, fmt, ...) pr_warn("UBI-%d warning: %s: " fmt "\n", \
56 __func__, ##__VA_ARGS__) 57 ubi->ubi_num, __func__, ##__VA_ARGS__)
57/* UBI error messages */ 58/* UBI error messages */
58#define ubi_err(fmt, ...) pr_err("UBI error: %s: " fmt "\n", \ 59#define ubi_err(ubi, fmt, ...) pr_err("UBI-%d error: %s: " fmt "\n", \
59 __func__, ##__VA_ARGS__) 60 ubi->ubi_num, __func__, ##__VA_ARGS__)
60 61
61/* Background thread name pattern */ 62/* Background thread name pattern */
62#define UBI_BGT_NAME_PATTERN "ubi_bgt%dd" 63#define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"
@@ -987,7 +988,7 @@ static inline void ubi_ro_mode(struct ubi_device *ubi)
987{ 988{
988 if (!ubi->ro_mode) { 989 if (!ubi->ro_mode) {
989 ubi->ro_mode = 1; 990 ubi->ro_mode = 1;
990 ubi_warn("switch to read-only mode"); 991 ubi_warn(ubi, "switch to read-only mode");
991 dump_stack(); 992 dump_stack();
992 } 993 }
993} 994}
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index ec2c2dc1c1ca..2a1b6e037e1a 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -133,6 +133,10 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
133 ubi_assert(!vol->updating && !vol->changing_leb); 133 ubi_assert(!vol->updating && !vol->changing_leb);
134 vol->updating = 1; 134 vol->updating = 1;
135 135
136 vol->upd_buf = vmalloc(ubi->leb_size);
137 if (!vol->upd_buf)
138 return -ENOMEM;
139
136 err = set_update_marker(ubi, vol); 140 err = set_update_marker(ubi, vol);
137 if (err) 141 if (err)
138 return err; 142 return err;
@@ -152,14 +156,12 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
152 err = clear_update_marker(ubi, vol, 0); 156 err = clear_update_marker(ubi, vol, 0);
153 if (err) 157 if (err)
154 return err; 158 return err;
159
160 vfree(vol->upd_buf);
155 vol->updating = 0; 161 vol->updating = 0;
156 return 0; 162 return 0;
157 } 163 }
158 164
159 vol->upd_buf = vmalloc(ubi->leb_size);
160 if (!vol->upd_buf)
161 return -ENOMEM;
162
163 vol->upd_ebs = div_u64(bytes + vol->usable_leb_size - 1, 165 vol->upd_ebs = div_u64(bytes + vol->usable_leb_size - 1,
164 vol->usable_leb_size); 166 vol->usable_leb_size);
165 vol->upd_bytes = bytes; 167 vol->upd_bytes = bytes;
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 8330703c098f..ff4d97848d1c 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -223,7 +223,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
223 } 223 }
224 224
225 if (vol_id == UBI_VOL_NUM_AUTO) { 225 if (vol_id == UBI_VOL_NUM_AUTO) {
226 ubi_err("out of volume IDs"); 226 ubi_err(ubi, "out of volume IDs");
227 err = -ENFILE; 227 err = -ENFILE;
228 goto out_unlock; 228 goto out_unlock;
229 } 229 }
@@ -237,7 +237,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
237 /* Ensure that this volume does not exist */ 237 /* Ensure that this volume does not exist */
238 err = -EEXIST; 238 err = -EEXIST;
239 if (ubi->volumes[vol_id]) { 239 if (ubi->volumes[vol_id]) {
240 ubi_err("volume %d already exists", vol_id); 240 ubi_err(ubi, "volume %d already exists", vol_id);
241 goto out_unlock; 241 goto out_unlock;
242 } 242 }
243 243
@@ -246,7 +246,8 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
246 if (ubi->volumes[i] && 246 if (ubi->volumes[i] &&
247 ubi->volumes[i]->name_len == req->name_len && 247 ubi->volumes[i]->name_len == req->name_len &&
248 !strcmp(ubi->volumes[i]->name, req->name)) { 248 !strcmp(ubi->volumes[i]->name, req->name)) {
249 ubi_err("volume \"%s\" exists (ID %d)", req->name, i); 249 ubi_err(ubi, "volume \"%s\" exists (ID %d)",
250 req->name, i);
250 goto out_unlock; 251 goto out_unlock;
251 } 252 }
252 253
@@ -257,9 +258,10 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
257 258
258 /* Reserve physical eraseblocks */ 259 /* Reserve physical eraseblocks */
259 if (vol->reserved_pebs > ubi->avail_pebs) { 260 if (vol->reserved_pebs > ubi->avail_pebs) {
260 ubi_err("not enough PEBs, only %d available", ubi->avail_pebs); 261 ubi_err(ubi, "not enough PEBs, only %d available",
262 ubi->avail_pebs);
261 if (ubi->corr_peb_count) 263 if (ubi->corr_peb_count)
262 ubi_err("%d PEBs are corrupted and not used", 264 ubi_err(ubi, "%d PEBs are corrupted and not used",
263 ubi->corr_peb_count); 265 ubi->corr_peb_count);
264 err = -ENOSPC; 266 err = -ENOSPC;
265 goto out_unlock; 267 goto out_unlock;
@@ -314,7 +316,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
314 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); 316 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
315 err = cdev_add(&vol->cdev, dev, 1); 317 err = cdev_add(&vol->cdev, dev, 1);
316 if (err) { 318 if (err) {
317 ubi_err("cannot add character device"); 319 ubi_err(ubi, "cannot add character device");
318 goto out_mapping; 320 goto out_mapping;
319 } 321 }
320 322
@@ -326,7 +328,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
326 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); 328 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
327 err = device_register(&vol->dev); 329 err = device_register(&vol->dev);
328 if (err) { 330 if (err) {
329 ubi_err("cannot register device"); 331 ubi_err(ubi, "cannot register device");
330 goto out_cdev; 332 goto out_cdev;
331 } 333 }
332 334
@@ -386,7 +388,7 @@ out_unlock:
386 kfree(vol); 388 kfree(vol);
387 else 389 else
388 put_device(&vol->dev); 390 put_device(&vol->dev);
389 ubi_err("cannot create volume %d, error %d", vol_id, err); 391 ubi_err(ubi, "cannot create volume %d, error %d", vol_id, err);
390 return err; 392 return err;
391} 393}
392 394
@@ -454,7 +456,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
454 return err; 456 return err;
455 457
456out_err: 458out_err:
457 ubi_err("cannot remove volume %d, error %d", vol_id, err); 459 ubi_err(ubi, "cannot remove volume %d, error %d", vol_id, err);
458 spin_lock(&ubi->volumes_lock); 460 spin_lock(&ubi->volumes_lock);
459 ubi->volumes[vol_id] = vol; 461 ubi->volumes[vol_id] = vol;
460out_unlock: 462out_unlock:
@@ -487,7 +489,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
487 489
488 if (vol->vol_type == UBI_STATIC_VOLUME && 490 if (vol->vol_type == UBI_STATIC_VOLUME &&
489 reserved_pebs < vol->used_ebs) { 491 reserved_pebs < vol->used_ebs) {
490 ubi_err("too small size %d, %d LEBs contain data", 492 ubi_err(ubi, "too small size %d, %d LEBs contain data",
491 reserved_pebs, vol->used_ebs); 493 reserved_pebs, vol->used_ebs);
492 return -EINVAL; 494 return -EINVAL;
493 } 495 }
@@ -516,10 +518,10 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
516 if (pebs > 0) { 518 if (pebs > 0) {
517 spin_lock(&ubi->volumes_lock); 519 spin_lock(&ubi->volumes_lock);
518 if (pebs > ubi->avail_pebs) { 520 if (pebs > ubi->avail_pebs) {
519 ubi_err("not enough PEBs: requested %d, available %d", 521 ubi_err(ubi, "not enough PEBs: requested %d, available %d",
520 pebs, ubi->avail_pebs); 522 pebs, ubi->avail_pebs);
521 if (ubi->corr_peb_count) 523 if (ubi->corr_peb_count)
522 ubi_err("%d PEBs are corrupted and not used", 524 ubi_err(ubi, "%d PEBs are corrupted and not used",
523 ubi->corr_peb_count); 525 ubi->corr_peb_count);
524 spin_unlock(&ubi->volumes_lock); 526 spin_unlock(&ubi->volumes_lock);
525 err = -ENOSPC; 527 err = -ENOSPC;
@@ -643,7 +645,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
643 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); 645 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
644 err = cdev_add(&vol->cdev, dev, 1); 646 err = cdev_add(&vol->cdev, dev, 1);
645 if (err) { 647 if (err) {
646 ubi_err("cannot add character device for volume %d, error %d", 648 ubi_err(ubi, "cannot add character device for volume %d, error %d",
647 vol_id, err); 649 vol_id, err);
648 return err; 650 return err;
649 } 651 }
@@ -710,7 +712,7 @@ static int self_check_volume(struct ubi_device *ubi, int vol_id)
710 712
711 if (!vol) { 713 if (!vol) {
712 if (reserved_pebs) { 714 if (reserved_pebs) {
713 ubi_err("no volume info, but volume exists"); 715 ubi_err(ubi, "no volume info, but volume exists");
714 goto fail; 716 goto fail;
715 } 717 }
716 spin_unlock(&ubi->volumes_lock); 718 spin_unlock(&ubi->volumes_lock);
@@ -719,90 +721,91 @@ static int self_check_volume(struct ubi_device *ubi, int vol_id)
719 721
720 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || 722 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
721 vol->name_len < 0) { 723 vol->name_len < 0) {
722 ubi_err("negative values"); 724 ubi_err(ubi, "negative values");
723 goto fail; 725 goto fail;
724 } 726 }
725 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { 727 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
726 ubi_err("bad alignment"); 728 ubi_err(ubi, "bad alignment");
727 goto fail; 729 goto fail;
728 } 730 }
729 731
730 n = vol->alignment & (ubi->min_io_size - 1); 732 n = vol->alignment & (ubi->min_io_size - 1);
731 if (vol->alignment != 1 && n) { 733 if (vol->alignment != 1 && n) {
732 ubi_err("alignment is not multiple of min I/O unit"); 734 ubi_err(ubi, "alignment is not multiple of min I/O unit");
733 goto fail; 735 goto fail;
734 } 736 }
735 737
736 n = ubi->leb_size % vol->alignment; 738 n = ubi->leb_size % vol->alignment;
737 if (vol->data_pad != n) { 739 if (vol->data_pad != n) {
738 ubi_err("bad data_pad, has to be %lld", n); 740 ubi_err(ubi, "bad data_pad, has to be %lld", n);
739 goto fail; 741 goto fail;
740 } 742 }
741 743
742 if (vol->vol_type != UBI_DYNAMIC_VOLUME && 744 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
743 vol->vol_type != UBI_STATIC_VOLUME) { 745 vol->vol_type != UBI_STATIC_VOLUME) {
744 ubi_err("bad vol_type"); 746 ubi_err(ubi, "bad vol_type");
745 goto fail; 747 goto fail;
746 } 748 }
747 749
748 if (vol->upd_marker && vol->corrupted) { 750 if (vol->upd_marker && vol->corrupted) {
749 ubi_err("update marker and corrupted simultaneously"); 751 ubi_err(ubi, "update marker and corrupted simultaneously");
750 goto fail; 752 goto fail;
751 } 753 }
752 754
753 if (vol->reserved_pebs > ubi->good_peb_count) { 755 if (vol->reserved_pebs > ubi->good_peb_count) {
754 ubi_err("too large reserved_pebs"); 756 ubi_err(ubi, "too large reserved_pebs");
755 goto fail; 757 goto fail;
756 } 758 }
757 759
758 n = ubi->leb_size - vol->data_pad; 760 n = ubi->leb_size - vol->data_pad;
759 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { 761 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
760 ubi_err("bad usable_leb_size, has to be %lld", n); 762 ubi_err(ubi, "bad usable_leb_size, has to be %lld", n);
761 goto fail; 763 goto fail;
762 } 764 }
763 765
764 if (vol->name_len > UBI_VOL_NAME_MAX) { 766 if (vol->name_len > UBI_VOL_NAME_MAX) {
765 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX); 767 ubi_err(ubi, "too long volume name, max is %d",
768 UBI_VOL_NAME_MAX);
766 goto fail; 769 goto fail;
767 } 770 }
768 771
769 n = strnlen(vol->name, vol->name_len + 1); 772 n = strnlen(vol->name, vol->name_len + 1);
770 if (n != vol->name_len) { 773 if (n != vol->name_len) {
771 ubi_err("bad name_len %lld", n); 774 ubi_err(ubi, "bad name_len %lld", n);
772 goto fail; 775 goto fail;
773 } 776 }
774 777
775 n = (long long)vol->used_ebs * vol->usable_leb_size; 778 n = (long long)vol->used_ebs * vol->usable_leb_size;
776 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 779 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
777 if (vol->corrupted) { 780 if (vol->corrupted) {
778 ubi_err("corrupted dynamic volume"); 781 ubi_err(ubi, "corrupted dynamic volume");
779 goto fail; 782 goto fail;
780 } 783 }
781 if (vol->used_ebs != vol->reserved_pebs) { 784 if (vol->used_ebs != vol->reserved_pebs) {
782 ubi_err("bad used_ebs"); 785 ubi_err(ubi, "bad used_ebs");
783 goto fail; 786 goto fail;
784 } 787 }
785 if (vol->last_eb_bytes != vol->usable_leb_size) { 788 if (vol->last_eb_bytes != vol->usable_leb_size) {
786 ubi_err("bad last_eb_bytes"); 789 ubi_err(ubi, "bad last_eb_bytes");
787 goto fail; 790 goto fail;
788 } 791 }
789 if (vol->used_bytes != n) { 792 if (vol->used_bytes != n) {
790 ubi_err("bad used_bytes"); 793 ubi_err(ubi, "bad used_bytes");
791 goto fail; 794 goto fail;
792 } 795 }
793 } else { 796 } else {
794 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { 797 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
795 ubi_err("bad used_ebs"); 798 ubi_err(ubi, "bad used_ebs");
796 goto fail; 799 goto fail;
797 } 800 }
798 if (vol->last_eb_bytes < 0 || 801 if (vol->last_eb_bytes < 0 ||
799 vol->last_eb_bytes > vol->usable_leb_size) { 802 vol->last_eb_bytes > vol->usable_leb_size) {
800 ubi_err("bad last_eb_bytes"); 803 ubi_err(ubi, "bad last_eb_bytes");
801 goto fail; 804 goto fail;
802 } 805 }
803 if (vol->used_bytes < 0 || vol->used_bytes > n || 806 if (vol->used_bytes < 0 || vol->used_bytes > n ||
804 vol->used_bytes < n - vol->usable_leb_size) { 807 vol->used_bytes < n - vol->usable_leb_size) {
805 ubi_err("bad used_bytes"); 808 ubi_err(ubi, "bad used_bytes");
806 goto fail; 809 goto fail;
807 } 810 }
808 } 811 }
@@ -820,7 +823,7 @@ static int self_check_volume(struct ubi_device *ubi, int vol_id)
820 if (alignment != vol->alignment || data_pad != vol->data_pad || 823 if (alignment != vol->alignment || data_pad != vol->data_pad ||
821 upd_marker != vol->upd_marker || vol_type != vol->vol_type || 824 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
822 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { 825 name_len != vol->name_len || strncmp(name, vol->name, name_len)) {
823 ubi_err("volume info is different"); 826 ubi_err(ubi, "volume info is different");
824 goto fail; 827 goto fail;
825 } 828 }
826 829
@@ -828,7 +831,7 @@ static int self_check_volume(struct ubi_device *ubi, int vol_id)
828 return 0; 831 return 0;
829 832
830fail: 833fail:
831 ubi_err("self-check failed for volume %d", vol_id); 834 ubi_err(ubi, "self-check failed for volume %d", vol_id);
832 if (vol) 835 if (vol)
833 ubi_dump_vol_info(vol); 836 ubi_dump_vol_info(vol);
834 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); 837 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 07cac5f9ffb8..f8fc3081bbb4 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -30,9 +30,12 @@
30 * eraseblock stores one volume table copy, i.e. LEB 0 and LEB 1 duplicate each 30 * eraseblock stores one volume table copy, i.e. LEB 0 and LEB 1 duplicate each
31 * other. This redundancy guarantees robustness to unclean reboots. The volume 31 * other. This redundancy guarantees robustness to unclean reboots. The volume
32 * table is basically an array of volume table records. Each record contains 32 * table is basically an array of volume table records. Each record contains
33 * full information about the volume and protected by a CRC checksum. 33 * full information about the volume and protected by a CRC checksum. Note,
34 * nowadays we use the atomic LEB change operation when updating the volume
35 * table, so we do not really need 2 LEBs anymore, but we preserve the older
36 * design for the backward compatibility reasons.
34 * 37 *
35 * The volume table is changed, it is first changed in RAM. Then LEB 0 is 38 * When the volume table is changed, it is first changed in RAM. Then LEB 0 is
36 * erased, and the updated volume table is written back to LEB 0. Then same for 39 * erased, and the updated volume table is written back to LEB 0. Then same for
37 * LEB 1. This scheme guarantees recoverability from unclean reboots. 40 * LEB 1. This scheme guarantees recoverability from unclean reboots.
38 * 41 *
@@ -96,12 +99,8 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
96 99
97 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); 100 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
98 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { 101 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
99 err = ubi_eba_unmap_leb(ubi, layout_vol, i); 102 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
100 if (err) 103 ubi->vtbl_size);
101 return err;
102
103 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
104 ubi->vtbl_size);
105 if (err) 104 if (err)
106 return err; 105 return err;
107 } 106 }
@@ -148,12 +147,8 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
148 147
149 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; 148 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
150 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { 149 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
151 err = ubi_eba_unmap_leb(ubi, layout_vol, i); 150 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
152 if (err) 151 ubi->vtbl_size);
153 return err;
154
155 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
156 ubi->vtbl_size);
157 if (err) 152 if (err)
158 return err; 153 return err;
159 } 154 }
@@ -190,7 +185,7 @@ static int vtbl_check(const struct ubi_device *ubi,
190 185
191 crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC); 186 crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC);
192 if (be32_to_cpu(vtbl[i].crc) != crc) { 187 if (be32_to_cpu(vtbl[i].crc) != crc) {
193 ubi_err("bad CRC at record %u: %#08x, not %#08x", 188 ubi_err(ubi, "bad CRC at record %u: %#08x, not %#08x",
194 i, crc, be32_to_cpu(vtbl[i].crc)); 189 i, crc, be32_to_cpu(vtbl[i].crc));
195 ubi_dump_vtbl_record(&vtbl[i], i); 190 ubi_dump_vtbl_record(&vtbl[i], i);
196 return 1; 191 return 1;
@@ -224,7 +219,7 @@ static int vtbl_check(const struct ubi_device *ubi,
224 219
225 n = ubi->leb_size % alignment; 220 n = ubi->leb_size % alignment;
226 if (data_pad != n) { 221 if (data_pad != n) {
227 ubi_err("bad data_pad, has to be %d", n); 222 ubi_err(ubi, "bad data_pad, has to be %d", n);
228 err = 6; 223 err = 6;
229 goto bad; 224 goto bad;
230 } 225 }
@@ -240,7 +235,7 @@ static int vtbl_check(const struct ubi_device *ubi,
240 } 235 }
241 236
242 if (reserved_pebs > ubi->good_peb_count) { 237 if (reserved_pebs > ubi->good_peb_count) {
243 ubi_err("too large reserved_pebs %d, good PEBs %d", 238 ubi_err(ubi, "too large reserved_pebs %d, good PEBs %d",
244 reserved_pebs, ubi->good_peb_count); 239 reserved_pebs, ubi->good_peb_count);
245 err = 9; 240 err = 9;
246 goto bad; 241 goto bad;
@@ -270,7 +265,7 @@ static int vtbl_check(const struct ubi_device *ubi,
270 265
271 if (len1 > 0 && len1 == len2 && 266 if (len1 > 0 && len1 == len2 &&
272 !strncmp(vtbl[i].name, vtbl[n].name, len1)) { 267 !strncmp(vtbl[i].name, vtbl[n].name, len1)) {
273 ubi_err("volumes %d and %d have the same name \"%s\"", 268 ubi_err(ubi, "volumes %d and %d have the same name \"%s\"",
274 i, n, vtbl[i].name); 269 i, n, vtbl[i].name);
275 ubi_dump_vtbl_record(&vtbl[i], i); 270 ubi_dump_vtbl_record(&vtbl[i], i);
276 ubi_dump_vtbl_record(&vtbl[n], n); 271 ubi_dump_vtbl_record(&vtbl[n], n);
@@ -282,7 +277,7 @@ static int vtbl_check(const struct ubi_device *ubi,
282 return 0; 277 return 0;
283 278
284bad: 279bad:
285 ubi_err("volume table check failed: record %d, error %d", i, err); 280 ubi_err(ubi, "volume table check failed: record %d, error %d", i, err);
286 ubi_dump_vtbl_record(&vtbl[i], i); 281 ubi_dump_vtbl_record(&vtbl[i], i);
287 return -EINVAL; 282 return -EINVAL;
288} 283}
@@ -446,11 +441,11 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
446 leb_corrupted[1] = memcmp(leb[0], leb[1], 441 leb_corrupted[1] = memcmp(leb[0], leb[1],
447 ubi->vtbl_size); 442 ubi->vtbl_size);
448 if (leb_corrupted[1]) { 443 if (leb_corrupted[1]) {
449 ubi_warn("volume table copy #2 is corrupted"); 444 ubi_warn(ubi, "volume table copy #2 is corrupted");
450 err = create_vtbl(ubi, ai, 1, leb[0]); 445 err = create_vtbl(ubi, ai, 1, leb[0]);
451 if (err) 446 if (err)
452 goto out_free; 447 goto out_free;
453 ubi_msg("volume table was restored"); 448 ubi_msg(ubi, "volume table was restored");
454 } 449 }
455 450
456 /* Both LEB 1 and LEB 2 are OK and consistent */ 451 /* Both LEB 1 and LEB 2 are OK and consistent */
@@ -465,15 +460,15 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
465 } 460 }
466 if (leb_corrupted[1]) { 461 if (leb_corrupted[1]) {
467 /* Both LEB 0 and LEB 1 are corrupted */ 462 /* Both LEB 0 and LEB 1 are corrupted */
468 ubi_err("both volume tables are corrupted"); 463 ubi_err(ubi, "both volume tables are corrupted");
469 goto out_free; 464 goto out_free;
470 } 465 }
471 466
472 ubi_warn("volume table copy #1 is corrupted"); 467 ubi_warn(ubi, "volume table copy #1 is corrupted");
473 err = create_vtbl(ubi, ai, 0, leb[1]); 468 err = create_vtbl(ubi, ai, 0, leb[1]);
474 if (err) 469 if (err)
475 goto out_free; 470 goto out_free;
476 ubi_msg("volume table was restored"); 471 ubi_msg(ubi, "volume table was restored");
477 472
478 vfree(leb[0]); 473 vfree(leb[0]);
479 return leb[1]; 474 return leb[1];
@@ -562,7 +557,7 @@ static int init_volumes(struct ubi_device *ubi,
562 if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) { 557 if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) {
563 /* Auto re-size flag may be set only for one volume */ 558 /* Auto re-size flag may be set only for one volume */
564 if (ubi->autoresize_vol_id != -1) { 559 if (ubi->autoresize_vol_id != -1) {
565 ubi_err("more than one auto-resize volume (%d and %d)", 560 ubi_err(ubi, "more than one auto-resize volume (%d and %d)",
566 ubi->autoresize_vol_id, i); 561 ubi->autoresize_vol_id, i);
567 kfree(vol); 562 kfree(vol);
568 return -EINVAL; 563 return -EINVAL;
@@ -608,7 +603,7 @@ static int init_volumes(struct ubi_device *ubi,
608 * We found a static volume which misses several 603 * We found a static volume which misses several
609 * eraseblocks. Treat it as corrupted. 604 * eraseblocks. Treat it as corrupted.
610 */ 605 */
611 ubi_warn("static volume %d misses %d LEBs - corrupted", 606 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted",
612 av->vol_id, av->used_ebs - av->leb_count); 607 av->vol_id, av->used_ebs - av->leb_count);
613 vol->corrupted = 1; 608 vol->corrupted = 1;
614 continue; 609 continue;
@@ -646,10 +641,10 @@ static int init_volumes(struct ubi_device *ubi,
646 vol->ubi = ubi; 641 vol->ubi = ubi;
647 642
648 if (reserved_pebs > ubi->avail_pebs) { 643 if (reserved_pebs > ubi->avail_pebs) {
649 ubi_err("not enough PEBs, required %d, available %d", 644 ubi_err(ubi, "not enough PEBs, required %d, available %d",
650 reserved_pebs, ubi->avail_pebs); 645 reserved_pebs, ubi->avail_pebs);
651 if (ubi->corr_peb_count) 646 if (ubi->corr_peb_count)
652 ubi_err("%d PEBs are corrupted and not used", 647 ubi_err(ubi, "%d PEBs are corrupted and not used",
653 ubi->corr_peb_count); 648 ubi->corr_peb_count);
654 } 649 }
655 ubi->rsvd_pebs += reserved_pebs; 650 ubi->rsvd_pebs += reserved_pebs;
@@ -660,13 +655,14 @@ static int init_volumes(struct ubi_device *ubi,
660 655
661/** 656/**
662 * check_av - check volume attaching information. 657 * check_av - check volume attaching information.
658 * @ubi: UBI device description object
663 * @vol: UBI volume description object 659 * @vol: UBI volume description object
664 * @av: volume attaching information 660 * @av: volume attaching information
665 * 661 *
666 * This function returns zero if the volume attaching information is consistent 662 * This function returns zero if the volume attaching information is consistent
667 * to the data read from the volume tabla, and %-EINVAL if not. 663 * to the data read from the volume tabla, and %-EINVAL if not.
668 */ 664 */
669static int check_av(const struct ubi_volume *vol, 665static int check_av(const struct ubi_device *ubi, const struct ubi_volume *vol,
670 const struct ubi_ainf_volume *av) 666 const struct ubi_ainf_volume *av)
671{ 667{
672 int err; 668 int err;
@@ -694,7 +690,7 @@ static int check_av(const struct ubi_volume *vol,
694 return 0; 690 return 0;
695 691
696bad: 692bad:
697 ubi_err("bad attaching information, error %d", err); 693 ubi_err(ubi, "bad attaching information, error %d", err);
698 ubi_dump_av(av); 694 ubi_dump_av(av);
699 ubi_dump_vol_info(vol); 695 ubi_dump_vol_info(vol);
700 return -EINVAL; 696 return -EINVAL;
@@ -718,14 +714,15 @@ static int check_attaching_info(const struct ubi_device *ubi,
718 struct ubi_volume *vol; 714 struct ubi_volume *vol;
719 715
720 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) { 716 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
721 ubi_err("found %d volumes while attaching, maximum is %d + %d", 717 ubi_err(ubi, "found %d volumes while attaching, maximum is %d + %d",
722 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots); 718 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
723 return -EINVAL; 719 return -EINVAL;
724 } 720 }
725 721
726 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && 722 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
727 ai->highest_vol_id < UBI_INTERNAL_VOL_START) { 723 ai->highest_vol_id < UBI_INTERNAL_VOL_START) {
728 ubi_err("too large volume ID %d found", ai->highest_vol_id); 724 ubi_err(ubi, "too large volume ID %d found",
725 ai->highest_vol_id);
729 return -EINVAL; 726 return -EINVAL;
730 } 727 }
731 728
@@ -753,10 +750,10 @@ static int check_attaching_info(const struct ubi_device *ubi,
753 * reboot while the volume was being removed. Discard 750 * reboot while the volume was being removed. Discard
754 * these eraseblocks. 751 * these eraseblocks.
755 */ 752 */
756 ubi_msg("finish volume %d removal", av->vol_id); 753 ubi_msg(ubi, "finish volume %d removal", av->vol_id);
757 ubi_remove_av(ai, av); 754 ubi_remove_av(ai, av);
758 } else if (av) { 755 } else if (av) {
759 err = check_av(vol, av); 756 err = check_av(ubi, vol, av);
760 if (err) 757 if (err)
761 return err; 758 return err;
762 } 759 }
@@ -807,13 +804,13 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
807 if (IS_ERR(ubi->vtbl)) 804 if (IS_ERR(ubi->vtbl))
808 return PTR_ERR(ubi->vtbl); 805 return PTR_ERR(ubi->vtbl);
809 } else { 806 } else {
810 ubi_err("the layout volume was not found"); 807 ubi_err(ubi, "the layout volume was not found");
811 return -EINVAL; 808 return -EINVAL;
812 } 809 }
813 } else { 810 } else {
814 if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) { 811 if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) {
815 /* This must not happen with proper UBI images */ 812 /* This must not happen with proper UBI images */
816 ubi_err("too many LEBs (%d) in layout volume", 813 ubi_err(ubi, "too many LEBs (%d) in layout volume",
817 av->leb_count); 814 av->leb_count);
818 return -EINVAL; 815 return -EINVAL;
819 } 816 }
@@ -862,7 +859,7 @@ static void self_vtbl_check(const struct ubi_device *ubi)
862 return; 859 return;
863 860
864 if (vtbl_check(ubi, ubi->vtbl)) { 861 if (vtbl_check(ubi, ubi->vtbl)) {
865 ubi_err("self-check failed"); 862 ubi_err(ubi, "self-check failed");
866 BUG(); 863 BUG();
867 } 864 }
868} 865}
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 6654f191868e..834f6fe1f5fa 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -253,7 +253,7 @@ static int do_work(struct ubi_device *ubi)
253 */ 253 */
254 err = wrk->func(ubi, wrk, 0); 254 err = wrk->func(ubi, wrk, 0);
255 if (err) 255 if (err)
256 ubi_err("work failed with error code %d", err); 256 ubi_err(ubi, "work failed with error code %d", err);
257 up_read(&ubi->work_sem); 257 up_read(&ubi->work_sem);
258 258
259 return err; 259 return err;
@@ -470,8 +470,11 @@ struct ubi_wl_entry *ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
470{ 470{
471 struct ubi_wl_entry *e = NULL; 471 struct ubi_wl_entry *e = NULL;
472 472
473 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) 473 if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1)) {
474 ubi_warn(ubi, "Can't get peb for fastmap:anchor=%d, free_cnt=%d, reserved=%d",
475 anchor, ubi->free_count, ubi->beb_rsvd_pebs);
474 goto out; 476 goto out;
477 }
475 478
476 if (anchor) 479 if (anchor)
477 e = find_anchor_wl_entry(&ubi->free); 480 e = find_anchor_wl_entry(&ubi->free);
@@ -507,7 +510,7 @@ static int __wl_get_peb(struct ubi_device *ubi)
507retry: 510retry:
508 if (!ubi->free.rb_node) { 511 if (!ubi->free.rb_node) {
509 if (ubi->works_count == 0) { 512 if (ubi->works_count == 0) {
510 ubi_err("no free eraseblocks"); 513 ubi_err(ubi, "no free eraseblocks");
511 ubi_assert(list_empty(&ubi->works)); 514 ubi_assert(list_empty(&ubi->works));
512 return -ENOSPC; 515 return -ENOSPC;
513 } 516 }
@@ -520,7 +523,7 @@ retry:
520 523
521 e = find_mean_wl_entry(ubi, &ubi->free); 524 e = find_mean_wl_entry(ubi, &ubi->free);
522 if (!e) { 525 if (!e) {
523 ubi_err("no free eraseblocks"); 526 ubi_err(ubi, "no free eraseblocks");
524 return -ENOSPC; 527 return -ENOSPC;
525 } 528 }
526 529
@@ -692,7 +695,8 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
692 err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset, 695 err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
693 ubi->peb_size - ubi->vid_hdr_aloffset); 696 ubi->peb_size - ubi->vid_hdr_aloffset);
694 if (err) { 697 if (err) {
695 ubi_err("new PEB %d does not contain all 0xFF bytes", peb); 698 ubi_err(ubi, "new PEB %d does not contain all 0xFF bytes",
699 peb);
696 return err; 700 return err;
697 } 701 }
698 702
@@ -760,7 +764,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
760 * Erase counter overflow. Upgrade UBI and use 64-bit 764 * Erase counter overflow. Upgrade UBI and use 64-bit
761 * erase counters internally. 765 * erase counters internally.
762 */ 766 */
763 ubi_err("erase counter overflow at PEB %d, EC %llu", 767 ubi_err(ubi, "erase counter overflow at PEB %d, EC %llu",
764 e->pnum, ec); 768 e->pnum, ec);
765 err = -EINVAL; 769 err = -EINVAL;
766 goto out_free; 770 goto out_free;
@@ -1137,7 +1141,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1137 goto out_not_moved; 1141 goto out_not_moved;
1138 } 1142 }
1139 1143
1140 ubi_err("error %d while reading VID header from PEB %d", 1144 ubi_err(ubi, "error %d while reading VID header from PEB %d",
1141 err, e1->pnum); 1145 err, e1->pnum);
1142 goto out_error; 1146 goto out_error;
1143 } 1147 }
@@ -1181,7 +1185,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1181 * UBI from trying to move it over and over again. 1185 * UBI from trying to move it over and over again.
1182 */ 1186 */
1183 if (ubi->erroneous_peb_count > ubi->max_erroneous) { 1187 if (ubi->erroneous_peb_count > ubi->max_erroneous) {
1184 ubi_err("too many erroneous eraseblocks (%d)", 1188 ubi_err(ubi, "too many erroneous eraseblocks (%d)",
1185 ubi->erroneous_peb_count); 1189 ubi->erroneous_peb_count);
1186 goto out_error; 1190 goto out_error;
1187 } 1191 }
@@ -1197,7 +1201,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1197 1201
1198 /* The PEB has been successfully moved */ 1202 /* The PEB has been successfully moved */
1199 if (scrubbing) 1203 if (scrubbing)
1200 ubi_msg("scrubbed PEB %d (LEB %d:%d), data moved to PEB %d", 1204 ubi_msg(ubi, "scrubbed PEB %d (LEB %d:%d), data moved to PEB %d",
1201 e1->pnum, vol_id, lnum, e2->pnum); 1205 e1->pnum, vol_id, lnum, e2->pnum);
1202 ubi_free_vid_hdr(ubi, vid_hdr); 1206 ubi_free_vid_hdr(ubi, vid_hdr);
1203 1207
@@ -1212,7 +1216,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1212 1216
1213 err = do_sync_erase(ubi, e1, vol_id, lnum, 0); 1217 err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
1214 if (err) { 1218 if (err) {
1215 kmem_cache_free(ubi_wl_entry_slab, e1);
1216 if (e2) 1219 if (e2)
1217 kmem_cache_free(ubi_wl_entry_slab, e2); 1220 kmem_cache_free(ubi_wl_entry_slab, e2);
1218 goto out_ro; 1221 goto out_ro;
@@ -1226,10 +1229,8 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
1226 dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase", 1229 dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase",
1227 e2->pnum, vol_id, lnum); 1230 e2->pnum, vol_id, lnum);
1228 err = do_sync_erase(ubi, e2, vol_id, lnum, 0); 1231 err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
1229 if (err) { 1232 if (err)
1230 kmem_cache_free(ubi_wl_entry_slab, e2);
1231 goto out_ro; 1233 goto out_ro;
1232 }
1233 } 1234 }
1234 1235
1235 dbg_wl("done"); 1236 dbg_wl("done");
@@ -1265,19 +1266,18 @@ out_not_moved:
1265 1266
1266 ubi_free_vid_hdr(ubi, vid_hdr); 1267 ubi_free_vid_hdr(ubi, vid_hdr);
1267 err = do_sync_erase(ubi, e2, vol_id, lnum, torture); 1268 err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
1268 if (err) { 1269 if (err)
1269 kmem_cache_free(ubi_wl_entry_slab, e2);
1270 goto out_ro; 1270 goto out_ro;
1271 } 1271
1272 mutex_unlock(&ubi->move_mutex); 1272 mutex_unlock(&ubi->move_mutex);
1273 return 0; 1273 return 0;
1274 1274
1275out_error: 1275out_error:
1276 if (vol_id != -1) 1276 if (vol_id != -1)
1277 ubi_err("error %d while moving PEB %d to PEB %d", 1277 ubi_err(ubi, "error %d while moving PEB %d to PEB %d",
1278 err, e1->pnum, e2->pnum); 1278 err, e1->pnum, e2->pnum);
1279 else 1279 else
1280 ubi_err("error %d while moving PEB %d (LEB %d:%d) to PEB %d", 1280 ubi_err(ubi, "error %d while moving PEB %d (LEB %d:%d) to PEB %d",
1281 err, e1->pnum, vol_id, lnum, e2->pnum); 1281 err, e1->pnum, vol_id, lnum, e2->pnum);
1282 spin_lock(&ubi->wl_lock); 1282 spin_lock(&ubi->wl_lock);
1283 ubi->move_from = ubi->move_to = NULL; 1283 ubi->move_from = ubi->move_to = NULL;
@@ -1458,7 +1458,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1458 return err; 1458 return err;
1459 } 1459 }
1460 1460
1461 ubi_err("failed to erase PEB %d, error %d", pnum, err); 1461 ubi_err(ubi, "failed to erase PEB %d, error %d", pnum, err);
1462 kfree(wl_wrk); 1462 kfree(wl_wrk);
1463 1463
1464 if (err == -EINTR || err == -ENOMEM || err == -EAGAIN || 1464 if (err == -EINTR || err == -ENOMEM || err == -EAGAIN ||
@@ -1486,7 +1486,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1486 /* It is %-EIO, the PEB went bad */ 1486 /* It is %-EIO, the PEB went bad */
1487 1487
1488 if (!ubi->bad_allowed) { 1488 if (!ubi->bad_allowed) {
1489 ubi_err("bad physical eraseblock %d detected", pnum); 1489 ubi_err(ubi, "bad physical eraseblock %d detected", pnum);
1490 goto out_ro; 1490 goto out_ro;
1491 } 1491 }
1492 1492
@@ -1494,7 +1494,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1494 if (ubi->beb_rsvd_pebs == 0) { 1494 if (ubi->beb_rsvd_pebs == 0) {
1495 if (ubi->avail_pebs == 0) { 1495 if (ubi->avail_pebs == 0) {
1496 spin_unlock(&ubi->volumes_lock); 1496 spin_unlock(&ubi->volumes_lock);
1497 ubi_err("no reserved/available physical eraseblocks"); 1497 ubi_err(ubi, "no reserved/available physical eraseblocks");
1498 goto out_ro; 1498 goto out_ro;
1499 } 1499 }
1500 ubi->avail_pebs -= 1; 1500 ubi->avail_pebs -= 1;
@@ -1502,7 +1502,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1502 } 1502 }
1503 spin_unlock(&ubi->volumes_lock); 1503 spin_unlock(&ubi->volumes_lock);
1504 1504
1505 ubi_msg("mark PEB %d as bad", pnum); 1505 ubi_msg(ubi, "mark PEB %d as bad", pnum);
1506 err = ubi_io_mark_bad(ubi, pnum); 1506 err = ubi_io_mark_bad(ubi, pnum);
1507 if (err) 1507 if (err)
1508 goto out_ro; 1508 goto out_ro;
@@ -1523,11 +1523,12 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1523 ubi->good_peb_count -= 1; 1523 ubi->good_peb_count -= 1;
1524 ubi_calculate_reserved(ubi); 1524 ubi_calculate_reserved(ubi);
1525 if (available_consumed) 1525 if (available_consumed)
1526 ubi_warn("no PEBs in the reserved pool, used an available PEB"); 1526 ubi_warn(ubi, "no PEBs in the reserved pool, used an available PEB");
1527 else if (ubi->beb_rsvd_pebs) 1527 else if (ubi->beb_rsvd_pebs)
1528 ubi_msg("%d PEBs left in the reserve", ubi->beb_rsvd_pebs); 1528 ubi_msg(ubi, "%d PEBs left in the reserve",
1529 ubi->beb_rsvd_pebs);
1529 else 1530 else
1530 ubi_warn("last PEB from the reserve was used"); 1531 ubi_warn(ubi, "last PEB from the reserve was used");
1531 spin_unlock(&ubi->volumes_lock); 1532 spin_unlock(&ubi->volumes_lock);
1532 1533
1533 return err; 1534 return err;
@@ -1613,7 +1614,7 @@ retry:
1613 } else { 1614 } else {
1614 err = prot_queue_del(ubi, e->pnum); 1615 err = prot_queue_del(ubi, e->pnum);
1615 if (err) { 1616 if (err) {
1616 ubi_err("PEB %d not found", pnum); 1617 ubi_err(ubi, "PEB %d not found", pnum);
1617 ubi_ro_mode(ubi); 1618 ubi_ro_mode(ubi);
1618 spin_unlock(&ubi->wl_lock); 1619 spin_unlock(&ubi->wl_lock);
1619 return err; 1620 return err;
@@ -1646,7 +1647,7 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum)
1646{ 1647{
1647 struct ubi_wl_entry *e; 1648 struct ubi_wl_entry *e;
1648 1649
1649 ubi_msg("schedule PEB %d for scrubbing", pnum); 1650 ubi_msg(ubi, "schedule PEB %d for scrubbing", pnum);
1650 1651
1651retry: 1652retry:
1652 spin_lock(&ubi->wl_lock); 1653 spin_lock(&ubi->wl_lock);
@@ -1678,7 +1679,7 @@ retry:
1678 1679
1679 err = prot_queue_del(ubi, e->pnum); 1680 err = prot_queue_del(ubi, e->pnum);
1680 if (err) { 1681 if (err) {
1681 ubi_err("PEB %d not found", pnum); 1682 ubi_err(ubi, "PEB %d not found", pnum);
1682 ubi_ro_mode(ubi); 1683 ubi_ro_mode(ubi);
1683 spin_unlock(&ubi->wl_lock); 1684 spin_unlock(&ubi->wl_lock);
1684 return err; 1685 return err;
@@ -1798,15 +1799,18 @@ int ubi_thread(void *u)
1798 int failures = 0; 1799 int failures = 0;
1799 struct ubi_device *ubi = u; 1800 struct ubi_device *ubi = u;
1800 1801
1801 ubi_msg("background thread \"%s\" started, PID %d", 1802 ubi_msg(ubi, "background thread \"%s\" started, PID %d",
1802 ubi->bgt_name, task_pid_nr(current)); 1803 ubi->bgt_name, task_pid_nr(current));
1803 1804
1804 set_freezable(); 1805 set_freezable();
1805 for (;;) { 1806 for (;;) {
1806 int err; 1807 int err;
1807 1808
1808 if (kthread_should_stop()) 1809 if (kthread_should_stop()) {
1810 ubi_msg(ubi, "background thread \"%s\" should stop, PID %d",
1811 ubi->bgt_name, task_pid_nr(current));
1809 break; 1812 break;
1813 }
1810 1814
1811 if (try_to_freeze()) 1815 if (try_to_freeze())
1812 continue; 1816 continue;
@@ -1823,14 +1827,14 @@ int ubi_thread(void *u)
1823 1827
1824 err = do_work(ubi); 1828 err = do_work(ubi);
1825 if (err) { 1829 if (err) {
1826 ubi_err("%s: work failed with error code %d", 1830 ubi_err(ubi, "%s: work failed with error code %d",
1827 ubi->bgt_name, err); 1831 ubi->bgt_name, err);
1828 if (failures++ > WL_MAX_FAILURES) { 1832 if (failures++ > WL_MAX_FAILURES) {
1829 /* 1833 /*
1830 * Too many failures, disable the thread and 1834 * Too many failures, disable the thread and
1831 * switch to read-only mode. 1835 * switch to read-only mode.
1832 */ 1836 */
1833 ubi_msg("%s: %d consecutive failures", 1837 ubi_msg(ubi, "%s: %d consecutive failures",
1834 ubi->bgt_name, WL_MAX_FAILURES); 1838 ubi->bgt_name, WL_MAX_FAILURES);
1835 ubi_ro_mode(ubi); 1839 ubi_ro_mode(ubi);
1836 ubi->thread_enabled = 0; 1840 ubi->thread_enabled = 0;
@@ -1981,10 +1985,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
1981#endif 1985#endif
1982 1986
1983 if (ubi->avail_pebs < reserved_pebs) { 1987 if (ubi->avail_pebs < reserved_pebs) {
1984 ubi_err("no enough physical eraseblocks (%d, need %d)", 1988 ubi_err(ubi, "no enough physical eraseblocks (%d, need %d)",
1985 ubi->avail_pebs, reserved_pebs); 1989 ubi->avail_pebs, reserved_pebs);
1986 if (ubi->corr_peb_count) 1990 if (ubi->corr_peb_count)
1987 ubi_err("%d PEBs are corrupted and not used", 1991 ubi_err(ubi, "%d PEBs are corrupted and not used",
1988 ubi->corr_peb_count); 1992 ubi->corr_peb_count);
1989 goto out_free; 1993 goto out_free;
1990 } 1994 }
@@ -2072,8 +2076,8 @@ static int self_check_ec(struct ubi_device *ubi, int pnum, int ec)
2072 2076
2073 read_ec = be64_to_cpu(ec_hdr->ec); 2077 read_ec = be64_to_cpu(ec_hdr->ec);
2074 if (ec != read_ec && read_ec - ec > 1) { 2078 if (ec != read_ec && read_ec - ec > 1) {
2075 ubi_err("self-check failed for PEB %d", pnum); 2079 ubi_err(ubi, "self-check failed for PEB %d", pnum);
2076 ubi_err("read EC is %lld, should be %d", read_ec, ec); 2080 ubi_err(ubi, "read EC is %lld, should be %d", read_ec, ec);
2077 dump_stack(); 2081 dump_stack();
2078 err = 1; 2082 err = 1;
2079 } else 2083 } else
@@ -2102,7 +2106,7 @@ static int self_check_in_wl_tree(const struct ubi_device *ubi,
2102 if (in_wl_tree(e, root)) 2106 if (in_wl_tree(e, root))
2103 return 0; 2107 return 0;
2104 2108
2105 ubi_err("self-check failed for PEB %d, EC %d, RB-tree %p ", 2109 ubi_err(ubi, "self-check failed for PEB %d, EC %d, RB-tree %p ",
2106 e->pnum, e->ec, root); 2110 e->pnum, e->ec, root);
2107 dump_stack(); 2111 dump_stack();
2108 return -EINVAL; 2112 return -EINVAL;
@@ -2130,7 +2134,7 @@ static int self_check_in_pq(const struct ubi_device *ubi,
2130 if (p == e) 2134 if (p == e)
2131 return 0; 2135 return 0;
2132 2136
2133 ubi_err("self-check failed for PEB %d, EC %d, Protect queue", 2137 ubi_err(ubi, "self-check failed for PEB %d, EC %d, Protect queue",
2134 e->pnum, e->ec); 2138 e->pnum, e->ec);
2135 dump_stack(); 2139 dump_stack();
2136 return -EINVAL; 2140 return -EINVAL;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index b5b593c45270..538519ee37d9 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -262,6 +262,7 @@ static int write_begin_slow(struct address_space *mapping,
262 if (err) { 262 if (err) {
263 unlock_page(page); 263 unlock_page(page);
264 page_cache_release(page); 264 page_cache_release(page);
265 ubifs_release_budget(c, &req);
265 return err; 266 return err;
266 } 267 }
267 } 268 }
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index fb166e204441..f6ac3f29323c 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -571,7 +571,11 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
571 571
572 aligned_dlen = ALIGN(dlen, 8); 572 aligned_dlen = ALIGN(dlen, 8);
573 aligned_ilen = ALIGN(ilen, 8); 573 aligned_ilen = ALIGN(ilen, 8);
574
574 len = aligned_dlen + aligned_ilen + UBIFS_INO_NODE_SZ; 575 len = aligned_dlen + aligned_ilen + UBIFS_INO_NODE_SZ;
576 /* Make sure to also account for extended attributes */
577 len += host_ui->data_len;
578
575 dent = kmalloc(len, GFP_NOFS); 579 dent = kmalloc(len, GFP_NOFS);
576 if (!dent) 580 if (!dent)
577 return -ENOMEM; 581 return -ENOMEM;
@@ -648,7 +652,8 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
648 652
649 ino_key_init(c, &ino_key, dir->i_ino); 653 ino_key_init(c, &ino_key, dir->i_ino);
650 ino_offs += aligned_ilen; 654 ino_offs += aligned_ilen;
651 err = ubifs_tnc_add(c, &ino_key, lnum, ino_offs, UBIFS_INO_NODE_SZ); 655 err = ubifs_tnc_add(c, &ino_key, lnum, ino_offs,
656 UBIFS_INO_NODE_SZ + host_ui->data_len);
652 if (err) 657 if (err)
653 goto out_ro; 658 goto out_ro;
654 659