aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/io.c')
-rw-r--r--drivers/mtd/ubi/io.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 438914d05151..b0d8f4cede97 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -125,9 +125,9 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
125 * o %UBI_IO_BITFLIPS if all the requested data were successfully read, but 125 * o %UBI_IO_BITFLIPS if all the requested data were successfully read, but
126 * correctable bit-flips were detected; this is harmless but may indicate 126 * correctable bit-flips were detected; this is harmless but may indicate
127 * that this eraseblock may become bad soon (but do not have to); 127 * that this eraseblock may become bad soon (but do not have to);
128 * o %-EBADMSG if the MTD subsystem reported about data data integrity 128 * o %-EBADMSG if the MTD subsystem reported about data integrity problems, for
129 * problems, for example it can me an ECC error in case of NAND; this most 129 * example it can be an ECC error in case of NAND; this most probably means
130 * probably means that the data is corrupted; 130 * that the data is corrupted;
131 * o %-EIO if some I/O error occurred; 131 * o %-EIO if some I/O error occurred;
132 * o other negative error codes in case of other errors. 132 * o other negative error codes in case of other errors.
133 */ 133 */
@@ -298,7 +298,7 @@ retry:
298 memset(&ei, 0, sizeof(struct erase_info)); 298 memset(&ei, 0, sizeof(struct erase_info));
299 299
300 ei.mtd = ubi->mtd; 300 ei.mtd = ubi->mtd;
301 ei.addr = pnum * ubi->peb_size; 301 ei.addr = (loff_t)pnum * ubi->peb_size;
302 ei.len = ubi->peb_size; 302 ei.len = ubi->peb_size;
303 ei.callback = erase_callback; 303 ei.callback = erase_callback;
304 ei.priv = (unsigned long)&wq; 304 ei.priv = (unsigned long)&wq;
@@ -382,7 +382,7 @@ static int torture_peb(const struct ubi_device *ubi, int pnum)
382 void *buf; 382 void *buf;
383 int err, i, patt_count; 383 int err, i, patt_count;
384 384
385 buf = kmalloc(ubi->peb_size, GFP_KERNEL); 385 buf = vmalloc(ubi->peb_size);
386 if (!buf) 386 if (!buf)
387 return -ENOMEM; 387 return -ENOMEM;
388 388
@@ -437,7 +437,7 @@ out:
437 * physical eraseblock which means something is wrong with it. 437 * physical eraseblock which means something is wrong with it.
438 */ 438 */
439 err = -EIO; 439 err = -EIO;
440 kfree(buf); 440 vfree(buf);
441 return err; 441 return err;
442} 442}
443 443
@@ -557,9 +557,9 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
557 long long ec; 557 long long ec;
558 int vid_hdr_offset, leb_start; 558 int vid_hdr_offset, leb_start;
559 559
560 ec = ubi64_to_cpu(ec_hdr->ec); 560 ec = be64_to_cpu(ec_hdr->ec);
561 vid_hdr_offset = ubi32_to_cpu(ec_hdr->vid_hdr_offset); 561 vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset);
562 leb_start = ubi32_to_cpu(ec_hdr->data_offset); 562 leb_start = be32_to_cpu(ec_hdr->data_offset);
563 563
564 if (ec_hdr->version != UBI_VERSION) { 564 if (ec_hdr->version != UBI_VERSION) {
565 ubi_err("node with incompatible UBI version found: " 565 ubi_err("node with incompatible UBI version found: "
@@ -640,7 +640,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum,
640 read_err = err; 640 read_err = err;
641 } 641 }
642 642
643 magic = ubi32_to_cpu(ec_hdr->magic); 643 magic = be32_to_cpu(ec_hdr->magic);
644 if (magic != UBI_EC_HDR_MAGIC) { 644 if (magic != UBI_EC_HDR_MAGIC) {
645 /* 645 /*
646 * The magic field is wrong. Let's check if we have read all 646 * The magic field is wrong. Let's check if we have read all
@@ -684,7 +684,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum,
684 } 684 }
685 685
686 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 686 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
687 hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); 687 hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);
688 688
689 if (hdr_crc != crc) { 689 if (hdr_crc != crc) {
690 if (verbose) { 690 if (verbose) {
@@ -729,12 +729,12 @@ int ubi_io_write_ec_hdr(const struct ubi_device *ubi, int pnum,
729 dbg_io("write EC header to PEB %d", pnum); 729 dbg_io("write EC header to PEB %d", pnum);
730 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 730 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
731 731
732 ec_hdr->magic = cpu_to_ubi32(UBI_EC_HDR_MAGIC); 732 ec_hdr->magic = cpu_to_be32(UBI_EC_HDR_MAGIC);
733 ec_hdr->version = UBI_VERSION; 733 ec_hdr->version = UBI_VERSION;
734 ec_hdr->vid_hdr_offset = cpu_to_ubi32(ubi->vid_hdr_offset); 734 ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset);
735 ec_hdr->data_offset = cpu_to_ubi32(ubi->leb_start); 735 ec_hdr->data_offset = cpu_to_be32(ubi->leb_start);
736 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 736 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
737 ec_hdr->hdr_crc = cpu_to_ubi32(crc); 737 ec_hdr->hdr_crc = cpu_to_be32(crc);
738 738
739 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 739 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
740 if (err) 740 if (err)
@@ -757,13 +757,13 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
757{ 757{
758 int vol_type = vid_hdr->vol_type; 758 int vol_type = vid_hdr->vol_type;
759 int copy_flag = vid_hdr->copy_flag; 759 int copy_flag = vid_hdr->copy_flag;
760 int vol_id = ubi32_to_cpu(vid_hdr->vol_id); 760 int vol_id = be32_to_cpu(vid_hdr->vol_id);
761 int lnum = ubi32_to_cpu(vid_hdr->lnum); 761 int lnum = be32_to_cpu(vid_hdr->lnum);
762 int compat = vid_hdr->compat; 762 int compat = vid_hdr->compat;
763 int data_size = ubi32_to_cpu(vid_hdr->data_size); 763 int data_size = be32_to_cpu(vid_hdr->data_size);
764 int used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); 764 int used_ebs = be32_to_cpu(vid_hdr->used_ebs);
765 int data_pad = ubi32_to_cpu(vid_hdr->data_pad); 765 int data_pad = be32_to_cpu(vid_hdr->data_pad);
766 int data_crc = ubi32_to_cpu(vid_hdr->data_crc); 766 int data_crc = be32_to_cpu(vid_hdr->data_crc);
767 int usable_leb_size = ubi->leb_size - data_pad; 767 int usable_leb_size = ubi->leb_size - data_pad;
768 768
769 if (copy_flag != 0 && copy_flag != 1) { 769 if (copy_flag != 0 && copy_flag != 1) {
@@ -914,7 +914,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum,
914 read_err = err; 914 read_err = err;
915 } 915 }
916 916
917 magic = ubi32_to_cpu(vid_hdr->magic); 917 magic = be32_to_cpu(vid_hdr->magic);
918 if (magic != UBI_VID_HDR_MAGIC) { 918 if (magic != UBI_VID_HDR_MAGIC) {
919 /* 919 /*
920 * If we have read all 0xFF bytes, the VID header probably does 920 * If we have read all 0xFF bytes, the VID header probably does
@@ -957,7 +957,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum,
957 } 957 }
958 958
959 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); 959 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
960 hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); 960 hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
961 961
962 if (hdr_crc != crc) { 962 if (hdr_crc != crc) {
963 if (verbose) { 963 if (verbose) {
@@ -1007,10 +1007,10 @@ int ubi_io_write_vid_hdr(const struct ubi_device *ubi, int pnum,
1007 if (err) 1007 if (err)
1008 return err > 0 ? -EINVAL: err; 1008 return err > 0 ? -EINVAL: err;
1009 1009
1010 vid_hdr->magic = cpu_to_ubi32(UBI_VID_HDR_MAGIC); 1010 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
1011 vid_hdr->version = UBI_VERSION; 1011 vid_hdr->version = UBI_VERSION;
1012 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); 1012 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
1013 vid_hdr->hdr_crc = cpu_to_ubi32(crc); 1013 vid_hdr->hdr_crc = cpu_to_be32(crc);
1014 1014
1015 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1015 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
1016 if (err) 1016 if (err)
@@ -1060,7 +1060,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1060 int err; 1060 int err;
1061 uint32_t magic; 1061 uint32_t magic;
1062 1062
1063 magic = ubi32_to_cpu(ec_hdr->magic); 1063 magic = be32_to_cpu(ec_hdr->magic);
1064 if (magic != UBI_EC_HDR_MAGIC) { 1064 if (magic != UBI_EC_HDR_MAGIC) {
1065 ubi_err("bad magic %#08x, must be %#08x", 1065 ubi_err("bad magic %#08x, must be %#08x",
1066 magic, UBI_EC_HDR_MAGIC); 1066 magic, UBI_EC_HDR_MAGIC);
@@ -1105,7 +1105,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1105 goto exit; 1105 goto exit;
1106 1106
1107 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 1107 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
1108 hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); 1108 hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);
1109 if (hdr_crc != crc) { 1109 if (hdr_crc != crc) {
1110 ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); 1110 ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc);
1111 ubi_err("paranoid check failed for PEB %d", pnum); 1111 ubi_err("paranoid check failed for PEB %d", pnum);
@@ -1137,7 +1137,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
1137 int err; 1137 int err;
1138 uint32_t magic; 1138 uint32_t magic;
1139 1139
1140 magic = ubi32_to_cpu(vid_hdr->magic); 1140 magic = be32_to_cpu(vid_hdr->magic);
1141 if (magic != UBI_VID_HDR_MAGIC) { 1141 if (magic != UBI_VID_HDR_MAGIC) {
1142 ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x", 1142 ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x",
1143 magic, pnum, UBI_VID_HDR_MAGIC); 1143 magic, pnum, UBI_VID_HDR_MAGIC);
@@ -1187,7 +1187,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1187 goto exit; 1187 goto exit;
1188 1188
1189 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); 1189 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
1190 hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); 1190 hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);
1191 if (hdr_crc != crc) { 1191 if (hdr_crc != crc) {
1192 ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " 1192 ubi_err("bad VID header CRC at PEB %d, calculated %#08x, "
1193 "read %#08x", pnum, crc, hdr_crc); 1193 "read %#08x", pnum, crc, hdr_crc);
@@ -1224,9 +1224,10 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
1224 void *buf; 1224 void *buf;
1225 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; 1225 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
1226 1226
1227 buf = kzalloc(len, GFP_KERNEL); 1227 buf = vmalloc(len);
1228 if (!buf) 1228 if (!buf)
1229 return -ENOMEM; 1229 return -ENOMEM;
1230 memset(buf, 0, len);
1230 1231
1231 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); 1232 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
1232 if (err && err != -EUCLEAN) { 1233 if (err && err != -EUCLEAN) {
@@ -1242,7 +1243,7 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
1242 goto fail; 1243 goto fail;
1243 } 1244 }
1244 1245
1245 kfree(buf); 1246 vfree(buf);
1246 return 0; 1247 return 0;
1247 1248
1248fail: 1249fail:
@@ -1252,7 +1253,7 @@ fail:
1252 err = 1; 1253 err = 1;
1253error: 1254error:
1254 ubi_dbg_dump_stack(); 1255 ubi_dbg_dump_stack();
1255 kfree(buf); 1256 vfree(buf);
1256 return err; 1257 return err;
1257} 1258}
1258 1259