aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2011-09-20 21:34:25 -0400
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2011-09-21 02:19:06 -0400
commitd57f40544a41fdfe90fd863b6865138c5a82f1cc (patch)
tree4d5e8f6d0a62e8fa06ccfabd13fe9364b19db1b5
parent7387ce773256f446bdd0280b2449b635441f906e (diff)
mtd: utilize `mtd_is_*()' functions
Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
-rw-r--r--drivers/mtd/inftlcore.c4
-rw-r--r--drivers/mtd/mtdchar.c4
-rw-r--r--drivers/mtd/mtdconcat.c8
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/mtdpart.c8
-rw-r--r--drivers/mtd/mtdswap.c20
-rw-r--r--drivers/mtd/nand/diskonchip.c2
-rw-r--r--drivers/mtd/nand/nand_bbt.c4
-rw-r--r--drivers/mtd/nftlcore.c4
-rw-r--r--drivers/mtd/onenand/onenand_base.c10
-rw-r--r--drivers/mtd/sm_ftl.c4
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c28
-rw-r--r--drivers/mtd/tests/mtd_readtest.c2
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c8
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c2
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c8
-rw-r--r--drivers/mtd/tests/mtd_torturetest.c2
-rw-r--r--drivers/mtd/ubi/eba.c2
-rw-r--r--drivers/mtd/ubi/io.c24
-rw-r--r--drivers/mtd/ubi/kapi.c2
-rw-r--r--drivers/mtd/ubi/misc.c2
-rw-r--r--drivers/mtd/ubi/scan.c4
-rw-r--r--drivers/mtd/ubi/vtbl.c2
23 files changed, 78 insertions, 78 deletions
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 652065e47a79..dd034efd1875 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -346,7 +346,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
346 ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) + 346 ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
347 (block * SECTORSIZE), SECTORSIZE, &retlen, 347 (block * SECTORSIZE), SECTORSIZE, &retlen,
348 movebuf); 348 movebuf);
349 if (ret < 0 && ret != -EUCLEAN) { 349 if (ret < 0 && !mtd_is_bitflip(ret)) {
350 ret = mtd->read(mtd, 350 ret = mtd->read(mtd,
351 (inftl->EraseSize * BlockMap[block]) + 351 (inftl->EraseSize * BlockMap[block]) +
352 (block * SECTORSIZE), SECTORSIZE, 352 (block * SECTORSIZE), SECTORSIZE,
@@ -917,7 +917,7 @@ foundit:
917 int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer); 917 int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer);
918 918
919 /* Handle corrected bit flips gracefully */ 919 /* Handle corrected bit flips gracefully */
920 if (ret < 0 && ret != -EUCLEAN) 920 if (ret < 0 && !mtd_is_bitflip(ret))
921 return -EIO; 921 return -EIO;
922 } 922 }
923 return 0; 923 return 0;
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 8feb5fdcd97b..47be6e5cefe4 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -242,7 +242,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
242 * Userspace software which accesses NAND this way 242 * Userspace software which accesses NAND this way
243 * must be aware of the fact that it deals with NAND 243 * must be aware of the fact that it deals with NAND
244 */ 244 */
245 if (!ret || (ret == -EUCLEAN) || (ret == -EBADMSG)) { 245 if (!ret || mtd_is_bitflip_or_eccerr(ret)) {
246 *ppos += retlen; 246 *ppos += retlen;
247 if (copy_to_user(buf, kbuf, retlen)) { 247 if (copy_to_user(buf, kbuf, retlen)) {
248 kfree(kbuf); 248 kfree(kbuf);
@@ -491,7 +491,7 @@ static int mtd_do_readoob(struct file *file, struct mtd_info *mtd,
491 * does not calculate ECC for the OOB area, so do not rely on 491 * does not calculate ECC for the OOB area, so do not rely on
492 * this behavior unless you have replaced it with your own. 492 * this behavior unless you have replaced it with your own.
493 */ 493 */
494 if (ret == -EUCLEAN || ret == -EBADMSG) 494 if (mtd_is_bitflip_or_eccerr(ret))
495 return 0; 495 return 0;
496 496
497 return ret; 497 return ret;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index d3fabd144d6c..6df4d4d4eb92 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -95,10 +95,10 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
95 95
96 /* Save information about bitflips! */ 96 /* Save information about bitflips! */
97 if (unlikely(err)) { 97 if (unlikely(err)) {
98 if (err == -EBADMSG) { 98 if (mtd_is_eccerr(err)) {
99 mtd->ecc_stats.failed++; 99 mtd->ecc_stats.failed++;
100 ret = err; 100 ret = err;
101 } else if (err == -EUCLEAN) { 101 } else if (mtd_is_bitflip(err)) {
102 mtd->ecc_stats.corrected++; 102 mtd->ecc_stats.corrected++;
103 /* Do not overwrite -EBADMSG !! */ 103 /* Do not overwrite -EBADMSG !! */
104 if (!ret) 104 if (!ret)
@@ -279,10 +279,10 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
279 279
280 /* Save information about bitflips! */ 280 /* Save information about bitflips! */
281 if (unlikely(err)) { 281 if (unlikely(err)) {
282 if (err == -EBADMSG) { 282 if (mtd_is_eccerr(err)) {
283 mtd->ecc_stats.failed++; 283 mtd->ecc_stats.failed++;
284 ret = err; 284 ret = err;
285 } else if (err == -EUCLEAN) { 285 } else if (mtd_is_bitflip(err)) {
286 mtd->ecc_stats.corrected++; 286 mtd->ecc_stats.corrected++;
287 /* Do not overwrite -EBADMSG !! */ 287 /* Do not overwrite -EBADMSG !! */
288 if (!ret) 288 if (!ret)
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index e3e40f440323..1e2fa6236705 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -258,7 +258,7 @@ static void find_next_position(struct mtdoops_context *cxt)
258 ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, 258 ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE,
259 &retlen, (u_char *) &count[0]); 259 &retlen, (u_char *) &count[0]);
260 if (retlen != MTDOOPS_HEADER_SIZE || 260 if (retlen != MTDOOPS_HEADER_SIZE ||
261 (ret < 0 && ret != -EUCLEAN)) { 261 (ret < 0 && !mtd_is_bitflip(ret))) {
262 printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n", 262 printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n",
263 page * record_size, retlen, 263 page * record_size, retlen,
264 MTDOOPS_HEADER_SIZE, ret); 264 MTDOOPS_HEADER_SIZE, ret);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index cd7785aa1649..a0bd2de4752b 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -73,9 +73,9 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
73 res = part->master->read(part->master, from + part->offset, 73 res = part->master->read(part->master, from + part->offset,
74 len, retlen, buf); 74 len, retlen, buf);
75 if (unlikely(res)) { 75 if (unlikely(res)) {
76 if (res == -EUCLEAN) 76 if (mtd_is_bitflip(res))
77 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected; 77 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected;
78 if (res == -EBADMSG) 78 if (mtd_is_eccerr(res))
79 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed; 79 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed;
80 } 80 }
81 return res; 81 return res;
@@ -142,9 +142,9 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
142 142
143 res = part->master->read_oob(part->master, from + part->offset, ops); 143 res = part->master->read_oob(part->master, from + part->offset, ops);
144 if (unlikely(res)) { 144 if (unlikely(res)) {
145 if (res == -EUCLEAN) 145 if (mtd_is_bitflip(res))
146 mtd->ecc_stats.corrected++; 146 mtd->ecc_stats.corrected++;
147 if (res == -EBADMSG) 147 if (mtd_is_eccerr(res))
148 mtd->ecc_stats.failed++; 148 mtd->ecc_stats.failed++;
149 } 149 }
150 return res; 150 return res;
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 910309f260f8..bd9590c723e4 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -314,7 +314,7 @@ static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from,
314{ 314{
315 int ret = d->mtd->read_oob(d->mtd, from, ops); 315 int ret = d->mtd->read_oob(d->mtd, from, ops);
316 316
317 if (ret == -EUCLEAN) 317 if (mtd_is_bitflip(ret))
318 return ret; 318 return ret;
319 319
320 if (ret) { 320 if (ret) {
@@ -354,7 +354,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
354 354
355 ret = mtdswap_read_oob(d, offset, &ops); 355 ret = mtdswap_read_oob(d, offset, &ops);
356 356
357 if (ret && ret != -EUCLEAN) 357 if (ret && !mtd_is_bitflip(ret))
358 return ret; 358 return ret;
359 359
360 data = (struct mtdswap_oobdata *)d->oob_buf; 360 data = (struct mtdswap_oobdata *)d->oob_buf;
@@ -363,7 +363,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
363 363
364 if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) { 364 if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) {
365 eb->erase_count = le32_to_cpu(data->count); 365 eb->erase_count = le32_to_cpu(data->count);
366 if (ret == -EUCLEAN) 366 if (mtd_is_bitflip(ret))
367 ret = MTDSWAP_SCANNED_BITFLIP; 367 ret = MTDSWAP_SCANNED_BITFLIP;
368 else { 368 else {
369 if (le16_to_cpu(data2->magic) == MTDSWAP_MAGIC_DIRTY) 369 if (le16_to_cpu(data2->magic) == MTDSWAP_MAGIC_DIRTY)
@@ -408,7 +408,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb,
408 if (ret) { 408 if (ret) {
409 dev_warn(d->dev, "Write OOB failed for block at %08llx " 409 dev_warn(d->dev, "Write OOB failed for block at %08llx "
410 "error %d\n", offset, ret); 410 "error %d\n", offset, ret);
411 if (ret == -EIO || ret == -EBADMSG) 411 if (ret == -EIO || mtd_is_eccerr(ret))
412 mtdswap_handle_write_error(d, eb); 412 mtdswap_handle_write_error(d, eb);
413 return ret; 413 return ret;
414 } 414 }
@@ -628,7 +628,7 @@ static int mtdswap_map_free_block(struct mtdswap_dev *d, unsigned int page,
628 TREE_COUNT(d, CLEAN)--; 628 TREE_COUNT(d, CLEAN)--;
629 629
630 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY); 630 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY);
631 } while (ret == -EIO || ret == -EBADMSG); 631 } while (ret == -EIO || mtd_is_eccerr(ret));
632 632
633 if (ret) 633 if (ret)
634 return ret; 634 return ret;
@@ -678,7 +678,7 @@ retry:
678 ret = mtdswap_map_free_block(d, page, bp); 678 ret = mtdswap_map_free_block(d, page, bp);
679 eb = d->eb_data + (*bp / d->pages_per_eblk); 679 eb = d->eb_data + (*bp / d->pages_per_eblk);
680 680
681 if (ret == -EIO || ret == -EBADMSG) { 681 if (ret == -EIO || mtd_is_eccerr(ret)) {
682 d->curr_write = NULL; 682 d->curr_write = NULL;
683 eb->active_count--; 683 eb->active_count--;
684 d->revmap[*bp] = PAGE_UNDEF; 684 d->revmap[*bp] = PAGE_UNDEF;
@@ -690,7 +690,7 @@ retry:
690 690
691 writepos = (loff_t)*bp << PAGE_SHIFT; 691 writepos = (loff_t)*bp << PAGE_SHIFT;
692 ret = mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf); 692 ret = mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf);
693 if (ret == -EIO || ret == -EBADMSG) { 693 if (ret == -EIO || mtd_is_eccerr(ret)) {
694 d->curr_write_pos--; 694 d->curr_write_pos--;
695 eb->active_count--; 695 eb->active_count--;
696 d->revmap[*bp] = PAGE_UNDEF; 696 d->revmap[*bp] = PAGE_UNDEF;
@@ -738,7 +738,7 @@ static int mtdswap_move_block(struct mtdswap_dev *d, unsigned int oldblock,
738retry: 738retry:
739 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf); 739 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf);
740 740
741 if (ret < 0 && ret != -EUCLEAN) { 741 if (ret < 0 && !mtd_is_bitflip(ret)) {
742 oldeb = d->eb_data + oldblock / d->pages_per_eblk; 742 oldeb = d->eb_data + oldblock / d->pages_per_eblk;
743 oldeb->flags |= EBLOCK_READERR; 743 oldeb->flags |= EBLOCK_READERR;
744 744
@@ -1016,7 +1016,7 @@ static int mtdswap_gc(struct mtdswap_dev *d, unsigned int background)
1016 1016
1017 if (ret == 0) 1017 if (ret == 0)
1018 mtdswap_rb_add(d, eb, MTDSWAP_CLEAN); 1018 mtdswap_rb_add(d, eb, MTDSWAP_CLEAN);
1019 else if (ret != -EIO && ret != -EBADMSG) 1019 else if (ret != -EIO && !mtd_is_eccerr(ret))
1020 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY); 1020 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY);
1021 1021
1022 return 0; 1022 return 0;
@@ -1164,7 +1164,7 @@ retry:
1164 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf); 1164 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf);
1165 1165
1166 d->mtd_read_count++; 1166 d->mtd_read_count++;
1167 if (ret == -EUCLEAN) { 1167 if (mtd_is_bitflip(ret)) {
1168 eb->flags |= EBLOCK_BITFLIP; 1168 eb->flags |= EBLOCK_BITFLIP;
1169 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP); 1169 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP);
1170 ret = 0; 1170 ret = 0;
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index de93a989aa54..ae8c60d604c1 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1031,7 +1031,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
1031 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); 1031 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
1032 else 1032 else
1033 WriteDOC(DOC_ECC_DIS, docptr, ECCConf); 1033 WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
1034 if (no_ecc_failures && (ret == -EBADMSG)) { 1034 if (no_ecc_failures && mtd_is_eccerr(ret)) {
1035 printk(KERN_ERR "suppressing ECC failure\n"); 1035 printk(KERN_ERR "suppressing ECC failure\n");
1036 ret = 0; 1036 ret = 0;
1037 } 1037 }
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 7dbfce4a1a5b..584bdcb3c61a 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -400,7 +400,7 @@ static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
400 400
401 ret = scan_read_raw_oob(mtd, buf, offs, readlen); 401 ret = scan_read_raw_oob(mtd, buf, offs, readlen);
402 /* Ignore ECC errors when checking for BBM */ 402 /* Ignore ECC errors when checking for BBM */
403 if (ret && ret != -EUCLEAN && ret != -EBADMSG) 403 if (ret && !mtd_is_bitflip_or_eccerr(ret))
404 return ret; 404 return ret;
405 405
406 for (j = 0; j < len; j++, buf += scanlen) { 406 for (j = 0; j < len; j++, buf += scanlen) {
@@ -430,7 +430,7 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
430 */ 430 */
431 ret = mtd->read_oob(mtd, offs, &ops); 431 ret = mtd->read_oob(mtd, offs, &ops);
432 /* Ignore ECC errors when checking for BBM */ 432 /* Ignore ECC errors when checking for BBM */
433 if (ret && ret != -EUCLEAN && ret != -EBADMSG) 433 if (ret && !mtd_is_bitflip_or_eccerr(ret))
434 return ret; 434 return ret;
435 435
436 if (check_short_pattern(buf, bd)) 436 if (check_short_pattern(buf, bd))
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index 272e3c03e324..cda77b562ad4 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -425,7 +425,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
425 425
426 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), 426 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
427 512, &retlen, movebuf); 427 512, &retlen, movebuf);
428 if (ret < 0 && ret != -EUCLEAN) { 428 if (ret < 0 && !mtd_is_bitflip(ret)) {
429 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) 429 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block])
430 + (block * 512), 512, &retlen, 430 + (block * 512), 512, &retlen,
431 movebuf); 431 movebuf);
@@ -773,7 +773,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
773 size_t retlen; 773 size_t retlen;
774 int res = mtd->read(mtd, ptr, 512, &retlen, buffer); 774 int res = mtd->read(mtd, ptr, 512, &retlen, buffer);
775 775
776 if (res < 0 && res != -EUCLEAN) 776 if (res < 0 && !mtd_is_bitflip(res))
777 return -EIO; 777 return -EIO;
778 } 778 }
779 return 0; 779 return 0;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index a52aa0f6b0c3..a8394730b4b6 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1079,7 +1079,7 @@ static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status)
1079 return status; 1079 return status;
1080 1080
1081 /* check if we failed due to uncorrectable error */ 1081 /* check if we failed due to uncorrectable error */
1082 if (status != -EBADMSG && status != ONENAND_BBT_READ_ECC_ERROR) 1082 if (!mtd_is_eccerr(status) && status != ONENAND_BBT_READ_ECC_ERROR)
1083 return status; 1083 return status;
1084 1084
1085 /* check if address lies in MLC region */ 1085 /* check if address lies in MLC region */
@@ -1159,7 +1159,7 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1159 if (unlikely(ret)) 1159 if (unlikely(ret))
1160 ret = onenand_recover_lsb(mtd, from, ret); 1160 ret = onenand_recover_lsb(mtd, from, ret);
1161 onenand_update_bufferram(mtd, from, !ret); 1161 onenand_update_bufferram(mtd, from, !ret);
1162 if (ret == -EBADMSG) 1162 if (mtd_is_eccerr(ret))
1163 ret = 0; 1163 ret = 0;
1164 if (ret) 1164 if (ret)
1165 break; 1165 break;
@@ -1255,7 +1255,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1255 this->command(mtd, ONENAND_CMD_READ, from, writesize); 1255 this->command(mtd, ONENAND_CMD_READ, from, writesize);
1256 ret = this->wait(mtd, FL_READING); 1256 ret = this->wait(mtd, FL_READING);
1257 onenand_update_bufferram(mtd, from, !ret); 1257 onenand_update_bufferram(mtd, from, !ret);
1258 if (ret == -EBADMSG) 1258 if (mtd_is_eccerr(ret))
1259 ret = 0; 1259 ret = 0;
1260 } 1260 }
1261 } 1261 }
@@ -1315,7 +1315,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1315 /* Now wait for load */ 1315 /* Now wait for load */
1316 ret = this->wait(mtd, FL_READING); 1316 ret = this->wait(mtd, FL_READING);
1317 onenand_update_bufferram(mtd, from, !ret); 1317 onenand_update_bufferram(mtd, from, !ret);
1318 if (ret == -EBADMSG) 1318 if (mtd_is_eccerr(ret))
1319 ret = 0; 1319 ret = 0;
1320 } 1320 }
1321 1321
@@ -1403,7 +1403,7 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
1403 if (unlikely(ret)) 1403 if (unlikely(ret))
1404 ret = onenand_recover_lsb(mtd, from, ret); 1404 ret = onenand_recover_lsb(mtd, from, ret);
1405 1405
1406 if (ret && ret != -EBADMSG) { 1406 if (ret && !mtd_is_eccerr(ret)) {
1407 printk(KERN_ERR "%s: read failed = 0x%x\n", 1407 printk(KERN_ERR "%s: read failed = 0x%x\n",
1408 __func__, ret); 1408 __func__, ret);
1409 break; 1409 break;
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index d927641cb0f5..fddb714e323c 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -281,7 +281,7 @@ again:
281 ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); 281 ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
282 282
283 /* Test for unknown errors */ 283 /* Test for unknown errors */
284 if (ret != 0 && ret != -EUCLEAN && ret != -EBADMSG) { 284 if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) {
285 dbg("read of block %d at zone %d, failed due to error (%d)", 285 dbg("read of block %d at zone %d, failed due to error (%d)",
286 block, zone, ret); 286 block, zone, ret);
287 goto again; 287 goto again;
@@ -306,7 +306,7 @@ again:
306 } 306 }
307 307
308 /* Test ECC*/ 308 /* Test ECC*/
309 if (ret == -EBADMSG || 309 if (mtd_is_eccerr(ret) ||
310 (ftl->smallpagenand && sm_correct_sector(buffer, oob))) { 310 (ftl->smallpagenand && sm_correct_sector(buffer, oob))) {
311 311
312 dbg("read of block %d at zone %d, failed due to ECC error", 312 dbg("read of block %d at zone %d, failed due to ECC error",
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 00b937e38c1d..186b14c02307 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -128,7 +128,7 @@ static int verify_eraseblock(int ebnum)
128 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { 128 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
129 /* Do a read to set the internal dataRAMs to different data */ 129 /* Do a read to set the internal dataRAMs to different data */
130 err = mtd->read(mtd, addr0, bufsize, &read, twopages); 130 err = mtd->read(mtd, addr0, bufsize, &read, twopages);
131 if (err == -EUCLEAN) 131 if (mtd_is_bitflip(err))
132 err = 0; 132 err = 0;
133 if (err || read != bufsize) { 133 if (err || read != bufsize) {
134 printk(PRINT_PREF "error: read failed at %#llx\n", 134 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -136,7 +136,7 @@ static int verify_eraseblock(int ebnum)
136 return err; 136 return err;
137 } 137 }
138 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); 138 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
139 if (err == -EUCLEAN) 139 if (mtd_is_bitflip(err))
140 err = 0; 140 err = 0;
141 if (err || read != bufsize) { 141 if (err || read != bufsize) {
142 printk(PRINT_PREF "error: read failed at %#llx\n", 142 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -146,7 +146,7 @@ static int verify_eraseblock(int ebnum)
146 memset(twopages, 0, bufsize); 146 memset(twopages, 0, bufsize);
147 read = 0; 147 read = 0;
148 err = mtd->read(mtd, addr, bufsize, &read, twopages); 148 err = mtd->read(mtd, addr, bufsize, &read, twopages);
149 if (err == -EUCLEAN) 149 if (mtd_is_bitflip(err))
150 err = 0; 150 err = 0;
151 if (err || read != bufsize) { 151 if (err || read != bufsize) {
152 printk(PRINT_PREF "error: read failed at %#llx\n", 152 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -164,7 +164,7 @@ static int verify_eraseblock(int ebnum)
164 unsigned long oldnext = next; 164 unsigned long oldnext = next;
165 /* Do a read to set the internal dataRAMs to different data */ 165 /* Do a read to set the internal dataRAMs to different data */
166 err = mtd->read(mtd, addr0, bufsize, &read, twopages); 166 err = mtd->read(mtd, addr0, bufsize, &read, twopages);
167 if (err == -EUCLEAN) 167 if (mtd_is_bitflip(err))
168 err = 0; 168 err = 0;
169 if (err || read != bufsize) { 169 if (err || read != bufsize) {
170 printk(PRINT_PREF "error: read failed at %#llx\n", 170 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -172,7 +172,7 @@ static int verify_eraseblock(int ebnum)
172 return err; 172 return err;
173 } 173 }
174 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); 174 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
175 if (err == -EUCLEAN) 175 if (mtd_is_bitflip(err))
176 err = 0; 176 err = 0;
177 if (err || read != bufsize) { 177 if (err || read != bufsize) {
178 printk(PRINT_PREF "error: read failed at %#llx\n", 178 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -182,7 +182,7 @@ static int verify_eraseblock(int ebnum)
182 memset(twopages, 0, bufsize); 182 memset(twopages, 0, bufsize);
183 read = 0; 183 read = 0;
184 err = mtd->read(mtd, addr, bufsize, &read, twopages); 184 err = mtd->read(mtd, addr, bufsize, &read, twopages);
185 if (err == -EUCLEAN) 185 if (mtd_is_bitflip(err))
186 err = 0; 186 err = 0;
187 if (err || read != bufsize) { 187 if (err || read != bufsize) {
188 printk(PRINT_PREF "error: read failed at %#llx\n", 188 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -231,7 +231,7 @@ static int crosstest(void)
231 read = 0; 231 read = 0;
232 addr = addrn - pgsize - pgsize; 232 addr = addrn - pgsize - pgsize;
233 err = mtd->read(mtd, addr, pgsize, &read, pp1); 233 err = mtd->read(mtd, addr, pgsize, &read, pp1);
234 if (err == -EUCLEAN) 234 if (mtd_is_bitflip(err))
235 err = 0; 235 err = 0;
236 if (err || read != pgsize) { 236 if (err || read != pgsize) {
237 printk(PRINT_PREF "error: read failed at %#llx\n", 237 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -244,7 +244,7 @@ static int crosstest(void)
244 read = 0; 244 read = 0;
245 addr = addrn - pgsize - pgsize - pgsize; 245 addr = addrn - pgsize - pgsize - pgsize;
246 err = mtd->read(mtd, addr, pgsize, &read, pp1); 246 err = mtd->read(mtd, addr, pgsize, &read, pp1);
247 if (err == -EUCLEAN) 247 if (mtd_is_bitflip(err))
248 err = 0; 248 err = 0;
249 if (err || read != pgsize) { 249 if (err || read != pgsize) {
250 printk(PRINT_PREF "error: read failed at %#llx\n", 250 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -258,7 +258,7 @@ static int crosstest(void)
258 addr = addr0; 258 addr = addr0;
259 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 259 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
260 err = mtd->read(mtd, addr, pgsize, &read, pp2); 260 err = mtd->read(mtd, addr, pgsize, &read, pp2);
261 if (err == -EUCLEAN) 261 if (mtd_is_bitflip(err))
262 err = 0; 262 err = 0;
263 if (err || read != pgsize) { 263 if (err || read != pgsize) {
264 printk(PRINT_PREF "error: read failed at %#llx\n", 264 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -272,7 +272,7 @@ static int crosstest(void)
272 addr = addrn - pgsize; 272 addr = addrn - pgsize;
273 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 273 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
274 err = mtd->read(mtd, addr, pgsize, &read, pp3); 274 err = mtd->read(mtd, addr, pgsize, &read, pp3);
275 if (err == -EUCLEAN) 275 if (mtd_is_bitflip(err))
276 err = 0; 276 err = 0;
277 if (err || read != pgsize) { 277 if (err || read != pgsize) {
278 printk(PRINT_PREF "error: read failed at %#llx\n", 278 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -286,7 +286,7 @@ static int crosstest(void)
286 addr = addr0; 286 addr = addr0;
287 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 287 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
288 err = mtd->read(mtd, addr, pgsize, &read, pp4); 288 err = mtd->read(mtd, addr, pgsize, &read, pp4);
289 if (err == -EUCLEAN) 289 if (mtd_is_bitflip(err))
290 err = 0; 290 err = 0;
291 if (err || read != pgsize) { 291 if (err || read != pgsize) {
292 printk(PRINT_PREF "error: read failed at %#llx\n", 292 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -345,7 +345,7 @@ static int erasecrosstest(void)
345 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 345 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
346 memset(readbuf, 0, pgsize); 346 memset(readbuf, 0, pgsize);
347 err = mtd->read(mtd, addr0, pgsize, &read, readbuf); 347 err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
348 if (err == -EUCLEAN) 348 if (mtd_is_bitflip(err))
349 err = 0; 349 err = 0;
350 if (err || read != pgsize) { 350 if (err || read != pgsize) {
351 printk(PRINT_PREF "error: read failed at %#llx\n", 351 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -383,7 +383,7 @@ static int erasecrosstest(void)
383 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 383 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
384 memset(readbuf, 0, pgsize); 384 memset(readbuf, 0, pgsize);
385 err = mtd->read(mtd, addr0, pgsize, &read, readbuf); 385 err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
386 if (err == -EUCLEAN) 386 if (mtd_is_bitflip(err))
387 err = 0; 387 err = 0;
388 if (err || read != pgsize) { 388 if (err || read != pgsize) {
389 printk(PRINT_PREF "error: read failed at %#llx\n", 389 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -439,7 +439,7 @@ static int erasetest(void)
439 439
440 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 440 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
441 err = mtd->read(mtd, addr0, pgsize, &read, twopages); 441 err = mtd->read(mtd, addr0, pgsize, &read, twopages);
442 if (err == -EUCLEAN) 442 if (mtd_is_bitflip(err))
443 err = 0; 443 err = 0;
444 if (err || read != pgsize) { 444 if (err || read != pgsize) {
445 printk(PRINT_PREF "error: read failed at %#llx\n", 445 printk(PRINT_PREF "error: read failed at %#llx\n",
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c
index 587e1e371c6c..756045345f00 100644
--- a/drivers/mtd/tests/mtd_readtest.c
+++ b/drivers/mtd/tests/mtd_readtest.c
@@ -75,7 +75,7 @@ static int read_eraseblock_by_page(int ebnum)
75 ops.datbuf = NULL; 75 ops.datbuf = NULL;
76 ops.oobbuf = oobbuf; 76 ops.oobbuf = oobbuf;
77 ret = mtd->read_oob(mtd, addr, &ops); 77 ret = mtd->read_oob(mtd, addr, &ops);
78 if ((ret && ret != -EUCLEAN) || 78 if ((ret && !mtd_is_bitflip(ret)) ||
79 ops.oobretlen != mtd->oobsize) { 79 ops.oobretlen != mtd->oobsize) {
80 printk(PRINT_PREF "error: read oob failed at " 80 printk(PRINT_PREF "error: read oob failed at "
81 "%#llx\n", (long long)addr); 81 "%#llx\n", (long long)addr);
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 627d4e2466a3..79d53ee62295 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -216,7 +216,7 @@ static int read_eraseblock(int ebnum)
216 216
217 err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf); 217 err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf);
218 /* Ignore corrected ECC errors */ 218 /* Ignore corrected ECC errors */
219 if (err == -EUCLEAN) 219 if (mtd_is_bitflip(err))
220 err = 0; 220 err = 0;
221 if (err || read != mtd->erasesize) { 221 if (err || read != mtd->erasesize) {
222 printk(PRINT_PREF "error: read failed at %#llx\n", addr); 222 printk(PRINT_PREF "error: read failed at %#llx\n", addr);
@@ -237,7 +237,7 @@ static int read_eraseblock_by_page(int ebnum)
237 for (i = 0; i < pgcnt; i++) { 237 for (i = 0; i < pgcnt; i++) {
238 err = mtd->read(mtd, addr, pgsize, &read, buf); 238 err = mtd->read(mtd, addr, pgsize, &read, buf);
239 /* Ignore corrected ECC errors */ 239 /* Ignore corrected ECC errors */
240 if (err == -EUCLEAN) 240 if (mtd_is_bitflip(err))
241 err = 0; 241 err = 0;
242 if (err || read != pgsize) { 242 if (err || read != pgsize) {
243 printk(PRINT_PREF "error: read failed at %#llx\n", 243 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -263,7 +263,7 @@ static int read_eraseblock_by_2pages(int ebnum)
263 for (i = 0; i < n; i++) { 263 for (i = 0; i < n; i++) {
264 err = mtd->read(mtd, addr, sz, &read, buf); 264 err = mtd->read(mtd, addr, sz, &read, buf);
265 /* Ignore corrected ECC errors */ 265 /* Ignore corrected ECC errors */
266 if (err == -EUCLEAN) 266 if (mtd_is_bitflip(err))
267 err = 0; 267 err = 0;
268 if (err || read != sz) { 268 if (err || read != sz) {
269 printk(PRINT_PREF "error: read failed at %#llx\n", 269 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -278,7 +278,7 @@ static int read_eraseblock_by_2pages(int ebnum)
278 if (pgcnt % 2) { 278 if (pgcnt % 2) {
279 err = mtd->read(mtd, addr, pgsize, &read, buf); 279 err = mtd->read(mtd, addr, pgsize, &read, buf);
280 /* Ignore corrected ECC errors */ 280 /* Ignore corrected ECC errors */
281 if (err == -EUCLEAN) 281 if (mtd_is_bitflip(err))
282 err = 0; 282 err = 0;
283 if (err || read != pgsize) { 283 if (err || read != pgsize) {
284 printk(PRINT_PREF "error: read failed at %#llx\n", 284 printk(PRINT_PREF "error: read failed at %#llx\n",
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 531625fc9259..3c9008adbe3b 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -154,7 +154,7 @@ static int do_read(void)
154 } 154 }
155 addr = eb * mtd->erasesize + offs; 155 addr = eb * mtd->erasesize + offs;
156 err = mtd->read(mtd, addr, len, &read, readbuf); 156 err = mtd->read(mtd, addr, len, &read, readbuf);
157 if (err == -EUCLEAN) 157 if (mtd_is_bitflip(err))
158 err = 0; 158 err = 0;
159 if (unlikely(err || read != len)) { 159 if (unlikely(err || read != len)) {
160 printk(PRINT_PREF "error: read failed at 0x%llx\n", 160 printk(PRINT_PREF "error: read failed at 0x%llx\n",
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 334eae53a3db..2b51842d08fa 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -198,7 +198,7 @@ static int verify_eraseblock(int ebnum)
198 read = 0; 198 read = 0;
199 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 199 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
200 if (unlikely(err || read != subpgsize)) { 200 if (unlikely(err || read != subpgsize)) {
201 if (err == -EUCLEAN && read == subpgsize) { 201 if (mtd_is_bitflip(err) && read == subpgsize) {
202 printk(PRINT_PREF "ECC correction at %#llx\n", 202 printk(PRINT_PREF "ECC correction at %#llx\n",
203 (long long)addr); 203 (long long)addr);
204 err = 0; 204 err = 0;
@@ -226,7 +226,7 @@ static int verify_eraseblock(int ebnum)
226 read = 0; 226 read = 0;
227 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 227 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
228 if (unlikely(err || read != subpgsize)) { 228 if (unlikely(err || read != subpgsize)) {
229 if (err == -EUCLEAN && read == subpgsize) { 229 if (mtd_is_bitflip(err) && read == subpgsize) {
230 printk(PRINT_PREF "ECC correction at %#llx\n", 230 printk(PRINT_PREF "ECC correction at %#llx\n",
231 (long long)addr); 231 (long long)addr);
232 err = 0; 232 err = 0;
@@ -264,7 +264,7 @@ static int verify_eraseblock2(int ebnum)
264 read = 0; 264 read = 0;
265 err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf); 265 err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf);
266 if (unlikely(err || read != subpgsize * k)) { 266 if (unlikely(err || read != subpgsize * k)) {
267 if (err == -EUCLEAN && read == subpgsize * k) { 267 if (mtd_is_bitflip(err) && read == subpgsize * k) {
268 printk(PRINT_PREF "ECC correction at %#llx\n", 268 printk(PRINT_PREF "ECC correction at %#llx\n",
269 (long long)addr); 269 (long long)addr);
270 err = 0; 270 err = 0;
@@ -298,7 +298,7 @@ static int verify_eraseblock_ff(int ebnum)
298 read = 0; 298 read = 0;
299 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 299 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
300 if (unlikely(err || read != subpgsize)) { 300 if (unlikely(err || read != subpgsize)) {
301 if (err == -EUCLEAN && read == subpgsize) { 301 if (mtd_is_bitflip(err) && read == subpgsize) {
302 printk(PRINT_PREF "ECC correction at %#llx\n", 302 printk(PRINT_PREF "ECC correction at %#llx\n",
303 (long long)addr); 303 (long long)addr);
304 err = 0; 304 err = 0;
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 5c6c3d248901..25786ce97c8e 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -138,7 +138,7 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf)
138 138
139retry: 139retry:
140 err = mtd->read(mtd, addr, len, &read, check_buf); 140 err = mtd->read(mtd, addr, len, &read, check_buf);
141 if (err == -EUCLEAN) 141 if (mtd_is_bitflip(err))
142 printk(PRINT_PREF "single bit flip occurred at EB %d " 142 printk(PRINT_PREF "single bit flip occurred at EB %d "
143 "MTD reported that it was fixed.\n", ebnum); 143 "MTD reported that it was fixed.\n", ebnum);
144 else if (err) { 144 else if (err) {
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 4be671815014..fb7f19b62d91 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -443,7 +443,7 @@ retry:
443 if (err == UBI_IO_BITFLIPS) { 443 if (err == UBI_IO_BITFLIPS) {
444 scrub = 1; 444 scrub = 1;
445 err = 0; 445 err = 0;
446 } else if (err == -EBADMSG) { 446 } else if (mtd_is_eccerr(err)) {
447 if (vol->vol_type == UBI_DYNAMIC_VOLUME) 447 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
448 goto out_unlock; 448 goto out_unlock;
449 scrub = 1; 449 scrub = 1;
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 6ba55c235873..f20b6f22f240 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -172,9 +172,9 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
172retry: 172retry:
173 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); 173 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
174 if (err) { 174 if (err) {
175 const char *errstr = (err == -EBADMSG) ? " (ECC error)" : ""; 175 const char *errstr = mtd_is_eccerr(err) ? " (ECC error)" : "";
176 176
177 if (err == -EUCLEAN) { 177 if (mtd_is_bitflip(err)) {
178 /* 178 /*
179 * -EUCLEAN is reported if there was a bit-flip which 179 * -EUCLEAN is reported if there was a bit-flip which
180 * was corrected, so this is harmless. 180 * was corrected, so this is harmless.
@@ -205,7 +205,7 @@ retry:
205 * all the requested data. But some buggy drivers might do 205 * all the requested data. But some buggy drivers might do
206 * this, so we change it to -EIO. 206 * this, so we change it to -EIO.
207 */ 207 */
208 if (read != len && err == -EBADMSG) { 208 if (read != len && mtd_is_eccerr(err)) {
209 ubi_assert(0); 209 ubi_assert(0);
210 err = -EIO; 210 err = -EIO;
211 } 211 }
@@ -469,7 +469,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
469 469
470out: 470out:
471 mutex_unlock(&ubi->buf_mutex); 471 mutex_unlock(&ubi->buf_mutex);
472 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) { 472 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
473 /* 473 /*
474 * If a bit-flip or data integrity error was detected, the test 474 * If a bit-flip or data integrity error was detected, the test
475 * has not passed because it happened on a freshly erased 475 * has not passed because it happened on a freshly erased
@@ -760,7 +760,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
760 760
761 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 761 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
762 if (read_err) { 762 if (read_err) {
763 if (read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) 763 if (read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
764 return read_err; 764 return read_err;
765 765
766 /* 766 /*
@@ -776,7 +776,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
776 776
777 magic = be32_to_cpu(ec_hdr->magic); 777 magic = be32_to_cpu(ec_hdr->magic);
778 if (magic != UBI_EC_HDR_MAGIC) { 778 if (magic != UBI_EC_HDR_MAGIC) {
779 if (read_err == -EBADMSG) 779 if (mtd_is_eccerr(read_err))
780 return UBI_IO_BAD_HDR_EBADMSG; 780 return UBI_IO_BAD_HDR_EBADMSG;
781 781
782 /* 782 /*
@@ -1032,12 +1032,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1032 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1032 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1033 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 1033 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
1034 ubi->vid_hdr_alsize); 1034 ubi->vid_hdr_alsize);
1035 if (read_err && read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) 1035 if (read_err && read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
1036 return read_err; 1036 return read_err;
1037 1037
1038 magic = be32_to_cpu(vid_hdr->magic); 1038 magic = be32_to_cpu(vid_hdr->magic);
1039 if (magic != UBI_VID_HDR_MAGIC) { 1039 if (magic != UBI_VID_HDR_MAGIC) {
1040 if (read_err == -EBADMSG) 1040 if (mtd_is_eccerr(read_err))
1041 return UBI_IO_BAD_HDR_EBADMSG; 1041 return UBI_IO_BAD_HDR_EBADMSG;
1042 1042
1043 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 1043 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
@@ -1219,7 +1219,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1219 return -ENOMEM; 1219 return -ENOMEM;
1220 1220
1221 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 1221 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
1222 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 1222 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
1223 goto exit; 1223 goto exit;
1224 1224
1225 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 1225 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -1306,7 +1306,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1306 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1306 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1307 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 1307 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
1308 ubi->vid_hdr_alsize); 1308 ubi->vid_hdr_alsize);
1309 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 1309 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
1310 goto exit; 1310 goto exit;
1311 1311
1312 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); 1312 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -1358,7 +1358,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1358 } 1358 }
1359 1359
1360 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1); 1360 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1);
1361 if (err && err != -EUCLEAN) 1361 if (err && !mtd_is_bitflip(err))
1362 goto out_free; 1362 goto out_free;
1363 1363
1364 for (i = 0; i < len; i++) { 1364 for (i = 0; i < len; i++) {
@@ -1422,7 +1422,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1422 } 1422 }
1423 1423
1424 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); 1424 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
1425 if (err && err != -EUCLEAN) { 1425 if (err && !mtd_is_bitflip(err)) {
1426 ubi_err("error %d while reading %d bytes from PEB %d:%d, " 1426 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
1427 "read %zd bytes", err, len, pnum, offset, read); 1427 "read %zd bytes", err, len, pnum, offset, read);
1428 goto error; 1428 goto error;
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index d39716e5b204..1a35fc5e3b40 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -410,7 +410,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
410 return 0; 410 return 0;
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 && err == -EBADMSG && 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("mark volume %d as corrupted", vol_id);
415 vol->corrupted = 1; 415 vol->corrupted = 1;
416 } 416 }
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index ff2a65c37f69..f6a7d7ac4b98 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -81,7 +81,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
81 81
82 err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1); 82 err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);
83 if (err) { 83 if (err) {
84 if (err == -EBADMSG) 84 if (mtd_is_eccerr(err))
85 err = 1; 85 err = 1;
86 break; 86 break;
87 } 87 }
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index a3a198f9b98d..0cb17d936b5a 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -395,7 +395,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
395 } 395 }
396 396
397 err = ubi_io_read_data(ubi, buf, pnum, 0, len); 397 err = ubi_io_read_data(ubi, buf, pnum, 0, len);
398 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 398 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
399 goto out_free_buf; 399 goto out_free_buf;
400 400
401 data_crc = be32_to_cpu(vid_hdr->data_crc); 401 data_crc = be32_to_cpu(vid_hdr->data_crc);
@@ -793,7 +793,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
793 793
794 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start, 794 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start,
795 ubi->leb_size); 795 ubi->leb_size);
796 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) { 796 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
797 /* 797 /*
798 * Bit-flips or integrity errors while reading the data area. 798 * Bit-flips or integrity errors while reading the data area.
799 * It is difficult to say for sure what type of corruption is 799 * It is difficult to say for sure what type of corruption is
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 4b50a3029b84..9ad18da1891d 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -423,7 +423,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
423 423
424 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0, 424 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
425 ubi->vtbl_size); 425 ubi->vtbl_size);
426 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) 426 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err))
427 /* 427 /*
428 * Scrub the PEB later. Note, -EBADMSG indicates an 428 * Scrub the PEB later. Note, -EBADMSG indicates an
429 * uncorrectable ECC error, but we have our own CRC and 429 * uncorrectable ECC error, but we have our own CRC and