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.c75
1 files changed, 35 insertions, 40 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index b0d8f4cede97..7c304eec78b5 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -98,8 +98,8 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
98static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); 98static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum);
99static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 99static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
100 const struct ubi_vid_hdr *vid_hdr); 100 const struct ubi_vid_hdr *vid_hdr);
101static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum, 101static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
102 int offset, int len); 102 int len);
103#else 103#else
104#define paranoid_check_not_bad(ubi, pnum) 0 104#define paranoid_check_not_bad(ubi, pnum) 0
105#define paranoid_check_peb_ec_hdr(ubi, pnum) 0 105#define paranoid_check_peb_ec_hdr(ubi, pnum) 0
@@ -202,8 +202,8 @@ retry:
202 * Note, in case of an error, it is possible that something was still written 202 * Note, in case of an error, it is possible that something was still written
203 * to the flash media, but may be some garbage. 203 * to the flash media, but may be some garbage.
204 */ 204 */
205int ubi_io_write(const struct ubi_device *ubi, const void *buf, int pnum, 205int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
206 int offset, int len) 206 int len)
207{ 207{
208 int err; 208 int err;
209 size_t written; 209 size_t written;
@@ -285,7 +285,7 @@ static void erase_callback(struct erase_info *ei)
285 * zero in case of success and a negative error code in case of failure. If 285 * zero in case of success and a negative error code in case of failure. If
286 * %-EIO is returned, the physical eraseblock most probably went bad. 286 * %-EIO is returned, the physical eraseblock most probably went bad.
287 */ 287 */
288static int do_sync_erase(const struct ubi_device *ubi, int pnum) 288static int do_sync_erase(struct ubi_device *ubi, int pnum)
289{ 289{
290 int err, retries = 0; 290 int err, retries = 0;
291 struct erase_info ei; 291 struct erase_info ei;
@@ -377,29 +377,25 @@ static uint8_t patterns[] = {0xa5, 0x5a, 0x0};
377 * test, a positive number of erase operations done if the test was 377 * test, a positive number of erase operations done if the test was
378 * successfully passed, and other negative error codes in case of other errors. 378 * successfully passed, and other negative error codes in case of other errors.
379 */ 379 */
380static int torture_peb(const struct ubi_device *ubi, int pnum) 380static int torture_peb(struct ubi_device *ubi, int pnum)
381{ 381{
382 void *buf;
383 int err, i, patt_count; 382 int err, i, patt_count;
384 383
385 buf = vmalloc(ubi->peb_size);
386 if (!buf)
387 return -ENOMEM;
388
389 patt_count = ARRAY_SIZE(patterns); 384 patt_count = ARRAY_SIZE(patterns);
390 ubi_assert(patt_count > 0); 385 ubi_assert(patt_count > 0);
391 386
387 mutex_lock(&ubi->buf_mutex);
392 for (i = 0; i < patt_count; i++) { 388 for (i = 0; i < patt_count; i++) {
393 err = do_sync_erase(ubi, pnum); 389 err = do_sync_erase(ubi, pnum);
394 if (err) 390 if (err)
395 goto out; 391 goto out;
396 392
397 /* Make sure the PEB contains only 0xFF bytes */ 393 /* Make sure the PEB contains only 0xFF bytes */
398 err = ubi_io_read(ubi, buf, pnum, 0, ubi->peb_size); 394 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
399 if (err) 395 if (err)
400 goto out; 396 goto out;
401 397
402 err = check_pattern(buf, 0xFF, ubi->peb_size); 398 err = check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size);
403 if (err == 0) { 399 if (err == 0) {
404 ubi_err("erased PEB %d, but a non-0xFF byte found", 400 ubi_err("erased PEB %d, but a non-0xFF byte found",
405 pnum); 401 pnum);
@@ -408,17 +404,17 @@ static int torture_peb(const struct ubi_device *ubi, int pnum)
408 } 404 }
409 405
410 /* Write a pattern and check it */ 406 /* Write a pattern and check it */
411 memset(buf, patterns[i], ubi->peb_size); 407 memset(ubi->peb_buf1, patterns[i], ubi->peb_size);
412 err = ubi_io_write(ubi, buf, pnum, 0, ubi->peb_size); 408 err = ubi_io_write(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
413 if (err) 409 if (err)
414 goto out; 410 goto out;
415 411
416 memset(buf, ~patterns[i], ubi->peb_size); 412 memset(ubi->peb_buf1, ~patterns[i], ubi->peb_size);
417 err = ubi_io_read(ubi, buf, pnum, 0, ubi->peb_size); 413 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
418 if (err) 414 if (err)
419 goto out; 415 goto out;
420 416
421 err = check_pattern(buf, patterns[i], ubi->peb_size); 417 err = check_pattern(ubi->peb_buf1, patterns[i], ubi->peb_size);
422 if (err == 0) { 418 if (err == 0) {
423 ubi_err("pattern %x checking failed for PEB %d", 419 ubi_err("pattern %x checking failed for PEB %d",
424 patterns[i], pnum); 420 patterns[i], pnum);
@@ -430,14 +426,17 @@ static int torture_peb(const struct ubi_device *ubi, int pnum)
430 err = patt_count; 426 err = patt_count;
431 427
432out: 428out:
433 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) 429 mutex_unlock(&ubi->buf_mutex);
430 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) {
434 /* 431 /*
435 * If a bit-flip or data integrity error was detected, the test 432 * If a bit-flip or data integrity error was detected, the test
436 * has not passed because it happened on a freshly erased 433 * has not passed because it happened on a freshly erased
437 * physical eraseblock which means something is wrong with it. 434 * physical eraseblock which means something is wrong with it.
438 */ 435 */
436 ubi_err("read problems on freshly erased PEB %d, must be bad",
437 pnum);
439 err = -EIO; 438 err = -EIO;
440 vfree(buf); 439 }
441 return err; 440 return err;
442} 441}
443 442
@@ -457,7 +456,7 @@ out:
457 * codes in case of other errors. Note, %-EIO means that the physical 456 * codes in case of other errors. Note, %-EIO means that the physical
458 * eraseblock is bad. 457 * eraseblock is bad.
459 */ 458 */
460int ubi_io_sync_erase(const struct ubi_device *ubi, int pnum, int torture) 459int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
461{ 460{
462 int err, ret = 0; 461 int err, ret = 0;
463 462
@@ -614,7 +613,7 @@ bad:
614 * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; 613 * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty;
615 * o a negative error code in case of failure. 614 * o a negative error code in case of failure.
616 */ 615 */
617int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum, 616int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
618 struct ubi_ec_hdr *ec_hdr, int verbose) 617 struct ubi_ec_hdr *ec_hdr, int verbose)
619{ 618{
620 int err, read_err = 0; 619 int err, read_err = 0;
@@ -720,7 +719,7 @@ int ubi_io_read_ec_hdr(const struct ubi_device *ubi, int pnum,
720 * case of failure. If %-EIO is returned, the physical eraseblock most probably 719 * case of failure. If %-EIO is returned, the physical eraseblock most probably
721 * went bad. 720 * went bad.
722 */ 721 */
723int ubi_io_write_ec_hdr(const struct ubi_device *ubi, int pnum, 722int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
724 struct ubi_ec_hdr *ec_hdr) 723 struct ubi_ec_hdr *ec_hdr)
725{ 724{
726 int err; 725 int err;
@@ -886,7 +885,7 @@ bad:
886 * header there); 885 * header there);
887 * o a negative error code in case of failure. 886 * o a negative error code in case of failure.
888 */ 887 */
889int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum, 888int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
890 struct ubi_vid_hdr *vid_hdr, int verbose) 889 struct ubi_vid_hdr *vid_hdr, int verbose)
891{ 890{
892 int err, read_err = 0; 891 int err, read_err = 0;
@@ -993,7 +992,7 @@ int ubi_io_read_vid_hdr(const struct ubi_device *ubi, int pnum,
993 * case of failure. If %-EIO is returned, the physical eraseblock probably went 992 * case of failure. If %-EIO is returned, the physical eraseblock probably went
994 * bad. 993 * bad.
995 */ 994 */
996int ubi_io_write_vid_hdr(const struct ubi_device *ubi, int pnum, 995int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
997 struct ubi_vid_hdr *vid_hdr) 996 struct ubi_vid_hdr *vid_hdr)
998{ 997{
999 int err; 998 int err;
@@ -1096,7 +1095,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1096 uint32_t crc, hdr_crc; 1095 uint32_t crc, hdr_crc;
1097 struct ubi_ec_hdr *ec_hdr; 1096 struct ubi_ec_hdr *ec_hdr;
1098 1097
1099 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); 1098 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
1100 if (!ec_hdr) 1099 if (!ec_hdr)
1101 return -ENOMEM; 1100 return -ENOMEM;
1102 1101
@@ -1176,7 +1175,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1176 struct ubi_vid_hdr *vid_hdr; 1175 struct ubi_vid_hdr *vid_hdr;
1177 void *p; 1176 void *p;
1178 1177
1179 vid_hdr = ubi_zalloc_vid_hdr(ubi); 1178 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
1180 if (!vid_hdr) 1179 if (!vid_hdr)
1181 return -ENOMEM; 1180 return -ENOMEM;
1182 1181
@@ -1216,44 +1215,40 @@ exit:
1216 * @offset of the physical eraseblock @pnum, %1 if not, and a negative error 1215 * @offset of the physical eraseblock @pnum, %1 if not, and a negative error
1217 * code if an error occurred. 1216 * code if an error occurred.
1218 */ 1217 */
1219static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum, 1218static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
1220 int offset, int len) 1219 int len)
1221{ 1220{
1222 size_t read; 1221 size_t read;
1223 int err; 1222 int err;
1224 void *buf;
1225 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; 1223 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
1226 1224
1227 buf = vmalloc(len); 1225 mutex_lock(&ubi->dbg_buf_mutex);
1228 if (!buf) 1226 err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf);
1229 return -ENOMEM;
1230 memset(buf, 0, len);
1231
1232 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
1233 if (err && err != -EUCLEAN) { 1227 if (err && err != -EUCLEAN) {
1234 ubi_err("error %d while reading %d bytes from PEB %d:%d, " 1228 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
1235 "read %zd bytes", err, len, pnum, offset, read); 1229 "read %zd bytes", err, len, pnum, offset, read);
1236 goto error; 1230 goto error;
1237 } 1231 }
1238 1232
1239 err = check_pattern(buf, 0xFF, len); 1233 err = check_pattern(ubi->dbg_peb_buf, 0xFF, len);
1240 if (err == 0) { 1234 if (err == 0) {
1241 ubi_err("flash region at PEB %d:%d, length %d does not " 1235 ubi_err("flash region at PEB %d:%d, length %d does not "
1242 "contain all 0xFF bytes", pnum, offset, len); 1236 "contain all 0xFF bytes", pnum, offset, len);
1243 goto fail; 1237 goto fail;
1244 } 1238 }
1239 mutex_unlock(&ubi->dbg_buf_mutex);
1245 1240
1246 vfree(buf);
1247 return 0; 1241 return 0;
1248 1242
1249fail: 1243fail:
1250 ubi_err("paranoid check failed for PEB %d", pnum); 1244 ubi_err("paranoid check failed for PEB %d", pnum);
1251 dbg_msg("hex dump of the %d-%d region", offset, offset + len); 1245 dbg_msg("hex dump of the %d-%d region", offset, offset + len);
1252 ubi_dbg_hexdump(buf, len); 1246 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1247 ubi->dbg_peb_buf, len, 1);
1253 err = 1; 1248 err = 1;
1254error: 1249error:
1255 ubi_dbg_dump_stack(); 1250 ubi_dbg_dump_stack();
1256 vfree(buf); 1251 mutex_unlock(&ubi->dbg_buf_mutex);
1257 return err; 1252 return err;
1258} 1253}
1259 1254