mtd: utilize `mtd_is_*()' functions
authorBrian Norris <computersforpeace@gmail.com>
Wed, 21 Sep 2011 01:34:25 +0000 (18:34 -0700)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Wed, 21 Sep 2011 06:19:06 +0000 (09:19 +0300)
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
23 files changed:
drivers/mtd/inftlcore.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdoops.c
drivers/mtd/mtdpart.c
drivers/mtd/mtdswap.c
drivers/mtd/nand/diskonchip.c
drivers/mtd/nand/nand_bbt.c
drivers/mtd/nftlcore.c
drivers/mtd/onenand/onenand_base.c
drivers/mtd/sm_ftl.c
drivers/mtd/tests/mtd_pagetest.c
drivers/mtd/tests/mtd_readtest.c
drivers/mtd/tests/mtd_speedtest.c
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_subpagetest.c
drivers/mtd/tests/mtd_torturetest.c
drivers/mtd/ubi/eba.c
drivers/mtd/ubi/io.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/misc.c
drivers/mtd/ubi/scan.c
drivers/mtd/ubi/vtbl.c

index 652065e47a79e46881bb5545d7c8e88864ac1cc4..dd034efd18751c8aaded3779f8ba85df06110bc5 100644 (file)
@@ -346,7 +346,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
                ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
                                (block * SECTORSIZE), SECTORSIZE, &retlen,
                                movebuf);
-               if (ret < 0 && ret != -EUCLEAN) {
+               if (ret < 0 && !mtd_is_bitflip(ret)) {
                        ret = mtd->read(mtd,
                                        (inftl->EraseSize * BlockMap[block]) +
                                        (block * SECTORSIZE), SECTORSIZE,
@@ -917,7 +917,7 @@ foundit:
                int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer);
 
                /* Handle corrected bit flips gracefully */
-               if (ret < 0 && ret != -EUCLEAN)
+               if (ret < 0 && !mtd_is_bitflip(ret))
                        return -EIO;
        }
        return 0;
index 8feb5fdcd97bdd543578a7dd93e997724820e351..47be6e5cefe425dbfdcf01545413636e38134042 100644 (file)
@@ -242,7 +242,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
                 * Userspace software which accesses NAND this way
                 * must be aware of the fact that it deals with NAND
                 */
-               if (!ret || (ret == -EUCLEAN) || (ret == -EBADMSG)) {
+               if (!ret || mtd_is_bitflip_or_eccerr(ret)) {
                        *ppos += retlen;
                        if (copy_to_user(buf, kbuf, retlen)) {
                                kfree(kbuf);
@@ -491,7 +491,7 @@ static int mtd_do_readoob(struct file *file, struct mtd_info *mtd,
         * does not calculate ECC for the OOB area, so do not rely on
         * this behavior unless you have replaced it with your own.
         */
-       if (ret == -EUCLEAN || ret == -EBADMSG)
+       if (mtd_is_bitflip_or_eccerr(ret))
                return 0;
 
        return ret;
index d3fabd144d6c380acd13029420a92957bb264fe2..6df4d4d4eb92bb585c9f0bc08815be208cda2d53 100644 (file)
@@ -95,10 +95,10 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
 
                /* Save information about bitflips! */
                if (unlikely(err)) {
-                       if (err == -EBADMSG) {
+                       if (mtd_is_eccerr(err)) {
                                mtd->ecc_stats.failed++;
                                ret = err;
-                       } else if (err == -EUCLEAN) {
+                       } else if (mtd_is_bitflip(err)) {
                                mtd->ecc_stats.corrected++;
                                /* Do not overwrite -EBADMSG !! */
                                if (!ret)
@@ -279,10 +279,10 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 
                /* Save information about bitflips! */
                if (unlikely(err)) {
-                       if (err == -EBADMSG) {
+                       if (mtd_is_eccerr(err)) {
                                mtd->ecc_stats.failed++;
                                ret = err;
-                       } else if (err == -EUCLEAN) {
+                       } else if (mtd_is_bitflip(err)) {
                                mtd->ecc_stats.corrected++;
                                /* Do not overwrite -EBADMSG !! */
                                if (!ret)
index e3e40f4403235540dc5ad5f6e3efd35aa981f647..1e2fa6236705941b9fea37b5f0d5bf4a713e56c7 100644 (file)
@@ -258,7 +258,7 @@ static void find_next_position(struct mtdoops_context *cxt)
                ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE,
                                &retlen, (u_char *) &count[0]);
                if (retlen != MTDOOPS_HEADER_SIZE ||
-                               (ret < 0 && ret != -EUCLEAN)) {
+                               (ret < 0 && !mtd_is_bitflip(ret))) {
                        printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n",
                               page * record_size, retlen,
                               MTDOOPS_HEADER_SIZE, ret);
index cd7785aa16496aed6aef2ce7468beee48cb1c3cb..a0bd2de4752baa3981b09a31b1efb0cc5f7b4a8b 100644 (file)
@@ -73,9 +73,9 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
        res = part->master->read(part->master, from + part->offset,
                                   len, retlen, buf);
        if (unlikely(res)) {
-               if (res == -EUCLEAN)
+               if (mtd_is_bitflip(res))
                        mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected;
-               if (res == -EBADMSG)
+               if (mtd_is_eccerr(res))
                        mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed;
        }
        return res;
@@ -142,9 +142,9 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
 
        res = part->master->read_oob(part->master, from + part->offset, ops);
        if (unlikely(res)) {
-               if (res == -EUCLEAN)
+               if (mtd_is_bitflip(res))
                        mtd->ecc_stats.corrected++;
-               if (res == -EBADMSG)
+               if (mtd_is_eccerr(res))
                        mtd->ecc_stats.failed++;
        }
        return res;
index 910309f260f889f8c8f92fc6e184e44eebba04f8..bd9590c723e41fcbb7055cc4dc61f49f402e340d 100644 (file)
@@ -314,7 +314,7 @@ static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from,
 {
        int ret = d->mtd->read_oob(d->mtd, from, ops);
 
-       if (ret == -EUCLEAN)
+       if (mtd_is_bitflip(ret))
                return ret;
 
        if (ret) {
@@ -354,7 +354,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
 
        ret = mtdswap_read_oob(d, offset, &ops);
 
-       if (ret && ret != -EUCLEAN)
+       if (ret && !mtd_is_bitflip(ret))
                return ret;
 
        data = (struct mtdswap_oobdata *)d->oob_buf;
@@ -363,7 +363,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
 
        if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) {
                eb->erase_count = le32_to_cpu(data->count);
-               if (ret == -EUCLEAN)
+               if (mtd_is_bitflip(ret))
                        ret = MTDSWAP_SCANNED_BITFLIP;
                else {
                        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,
        if (ret) {
                dev_warn(d->dev, "Write OOB failed for block at %08llx "
                        "error %d\n", offset, ret);
-               if (ret == -EIO || ret == -EBADMSG)
+               if (ret == -EIO || mtd_is_eccerr(ret))
                        mtdswap_handle_write_error(d, eb);
                return ret;
        }
@@ -628,7 +628,7 @@ static int mtdswap_map_free_block(struct mtdswap_dev *d, unsigned int page,
                        TREE_COUNT(d, CLEAN)--;
 
                        ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY);
-               } while (ret == -EIO || ret == -EBADMSG);
+               } while (ret == -EIO || mtd_is_eccerr(ret));
 
                if (ret)
                        return ret;
@@ -678,7 +678,7 @@ retry:
        ret = mtdswap_map_free_block(d, page, bp);
        eb = d->eb_data + (*bp / d->pages_per_eblk);
 
-       if (ret == -EIO || ret == -EBADMSG) {
+       if (ret == -EIO || mtd_is_eccerr(ret)) {
                d->curr_write = NULL;
                eb->active_count--;
                d->revmap[*bp] = PAGE_UNDEF;
@@ -690,7 +690,7 @@ retry:
 
        writepos = (loff_t)*bp << PAGE_SHIFT;
        ret =  mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf);
-       if (ret == -EIO || ret == -EBADMSG) {
+       if (ret == -EIO || mtd_is_eccerr(ret)) {
                d->curr_write_pos--;
                eb->active_count--;
                d->revmap[*bp] = PAGE_UNDEF;
@@ -738,7 +738,7 @@ static int mtdswap_move_block(struct mtdswap_dev *d, unsigned int oldblock,
 retry:
        ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf);
 
-       if (ret < 0 && ret != -EUCLEAN) {
+       if (ret < 0 && !mtd_is_bitflip(ret)) {
                oldeb = d->eb_data + oldblock / d->pages_per_eblk;
                oldeb->flags |= EBLOCK_READERR;
 
@@ -1016,7 +1016,7 @@ static int mtdswap_gc(struct mtdswap_dev *d, unsigned int background)
 
        if (ret == 0)
                mtdswap_rb_add(d, eb, MTDSWAP_CLEAN);
-       else if (ret != -EIO && ret != -EBADMSG)
+       else if (ret != -EIO && !mtd_is_eccerr(ret))
                mtdswap_rb_add(d, eb, MTDSWAP_DIRTY);
 
        return 0;
@@ -1164,7 +1164,7 @@ retry:
        ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf);
 
        d->mtd_read_count++;
-       if (ret == -EUCLEAN) {
+       if (mtd_is_bitflip(ret)) {
                eb->flags |= EBLOCK_BITFLIP;
                mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP);
                ret = 0;
index de93a989aa54866b92c29f09388e1cd57a78bfa4..ae8c60d604c147ec861c7798d0d8f3193682a8a5 100644 (file)
@@ -1031,7 +1031,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
                WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
        else
                WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
-       if (no_ecc_failures && (ret == -EBADMSG)) {
+       if (no_ecc_failures && mtd_is_eccerr(ret)) {
                printk(KERN_ERR "suppressing ECC failure\n");
                ret = 0;
        }
index 7dbfce4a1a5b66c6ffe77012ce4548f56b13c9d7..584bdcb3c61af981e6a081a97adfc4a8b106a357 100644 (file)
@@ -400,7 +400,7 @@ static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
 
        ret = scan_read_raw_oob(mtd, buf, offs, readlen);
        /* Ignore ECC errors when checking for BBM */
-       if (ret && ret != -EUCLEAN && ret != -EBADMSG)
+       if (ret && !mtd_is_bitflip_or_eccerr(ret))
                return ret;
 
        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,
                 */
                ret = mtd->read_oob(mtd, offs, &ops);
                /* Ignore ECC errors when checking for BBM */
-               if (ret && ret != -EUCLEAN && ret != -EBADMSG)
+               if (ret && !mtd_is_bitflip_or_eccerr(ret))
                        return ret;
 
                if (check_short_pattern(buf, bd))
index 272e3c03e324cd76be93059b05206cebc37ca56e..cda77b562ad43da9efd14f1cfb1ab4219583e9d8 100644 (file)
@@ -425,7 +425,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
 
                ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
                                512, &retlen, movebuf);
-               if (ret < 0 && ret != -EUCLEAN) {
+               if (ret < 0 && !mtd_is_bitflip(ret)) {
                        ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block])
                                        + (block * 512), 512, &retlen,
                                        movebuf);
@@ -773,7 +773,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
                size_t retlen;
                int res = mtd->read(mtd, ptr, 512, &retlen, buffer);
 
-               if (res < 0 && res != -EUCLEAN)
+               if (res < 0 && !mtd_is_bitflip(res))
                        return -EIO;
        }
        return 0;
index a52aa0f6b0c38f84857ca225fe92aaecee509b8c..a8394730b4b6fc7e9e84fcdd919e9a09c0b669da 100644 (file)
@@ -1079,7 +1079,7 @@ static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status)
                return status;
 
        /* check if we failed due to uncorrectable error */
-       if (status != -EBADMSG && status != ONENAND_BBT_READ_ECC_ERROR)
+       if (!mtd_is_eccerr(status) && status != ONENAND_BBT_READ_ECC_ERROR)
                return status;
 
        /* 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,
                        if (unlikely(ret))
                                ret = onenand_recover_lsb(mtd, from, ret);
                        onenand_update_bufferram(mtd, from, !ret);
-                       if (ret == -EBADMSG)
+                       if (mtd_is_eccerr(ret))
                                ret = 0;
                        if (ret)
                                break;
@@ -1255,7 +1255,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
                        this->command(mtd, ONENAND_CMD_READ, from, writesize);
                        ret = this->wait(mtd, FL_READING);
                        onenand_update_bufferram(mtd, from, !ret);
-                       if (ret == -EBADMSG)
+                       if (mtd_is_eccerr(ret))
                                ret = 0;
                }
        }
@@ -1315,7 +1315,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
                /* Now wait for load */
                ret = this->wait(mtd, FL_READING);
                onenand_update_bufferram(mtd, from, !ret);
-               if (ret == -EBADMSG)
+               if (mtd_is_eccerr(ret))
                        ret = 0;
        }
 
@@ -1403,7 +1403,7 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
                if (unlikely(ret))
                        ret = onenand_recover_lsb(mtd, from, ret);
 
-               if (ret && ret != -EBADMSG) {
+               if (ret && !mtd_is_eccerr(ret)) {
                        printk(KERN_ERR "%s: read failed = 0x%x\n",
                                __func__, ret);
                        break;
index d927641cb0f5c80171af6689b4e0181543aa51ea..fddb714e323cf3ea577b40c32e4abbb2aced5f29 100644 (file)
@@ -281,7 +281,7 @@ again:
        ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
 
        /* Test for unknown errors */
-       if (ret != 0 && ret != -EUCLEAN && ret != -EBADMSG) {
+       if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) {
                dbg("read of block %d at zone %d, failed due to error (%d)",
                        block, zone, ret);
                goto again;
@@ -306,7 +306,7 @@ again:
        }
 
        /* Test ECC*/
-       if (ret == -EBADMSG ||
+       if (mtd_is_eccerr(ret) ||
                (ftl->smallpagenand && sm_correct_sector(buffer, oob))) {
 
                dbg("read of block %d at zone %d, failed due to ECC error",
index 00b937e38c1d509abcda5cbd6cfc429c06b0807b..186b14c02307d6348d54f930450dac8588eeba72 100644 (file)
@@ -128,7 +128,7 @@ static int verify_eraseblock(int ebnum)
        for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
                /* Do a read to set the internal dataRAMs to different data */
                err = mtd->read(mtd, addr0, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -136,7 +136,7 @@ static int verify_eraseblock(int ebnum)
                        return err;
                }
                err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -146,7 +146,7 @@ static int verify_eraseblock(int ebnum)
                memset(twopages, 0, bufsize);
                read = 0;
                err = mtd->read(mtd, addr, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -164,7 +164,7 @@ static int verify_eraseblock(int ebnum)
                unsigned long oldnext = next;
                /* Do a read to set the internal dataRAMs to different data */
                err = mtd->read(mtd, addr0, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -172,7 +172,7 @@ static int verify_eraseblock(int ebnum)
                        return err;
                }
                err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -182,7 +182,7 @@ static int verify_eraseblock(int ebnum)
                memset(twopages, 0, bufsize);
                read = 0;
                err = mtd->read(mtd, addr, bufsize, &read, twopages);
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != bufsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -231,7 +231,7 @@ static int crosstest(void)
        read = 0;
        addr = addrn - pgsize - pgsize;
        err = mtd->read(mtd, addr, pgsize, &read, pp1);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -244,7 +244,7 @@ static int crosstest(void)
        read = 0;
        addr = addrn - pgsize - pgsize - pgsize;
        err = mtd->read(mtd, addr, pgsize, &read, pp1);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -258,7 +258,7 @@ static int crosstest(void)
        addr = addr0;
        printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
        err = mtd->read(mtd, addr, pgsize, &read, pp2);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -272,7 +272,7 @@ static int crosstest(void)
        addr = addrn - pgsize;
        printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
        err = mtd->read(mtd, addr, pgsize, &read, pp3);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -286,7 +286,7 @@ static int crosstest(void)
        addr = addr0;
        printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
        err = mtd->read(mtd, addr, pgsize, &read, pp4);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -345,7 +345,7 @@ static int erasecrosstest(void)
        printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
        memset(readbuf, 0, pgsize);
        err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -383,7 +383,7 @@ static int erasecrosstest(void)
        printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
        memset(readbuf, 0, pgsize);
        err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -439,7 +439,7 @@ static int erasetest(void)
 
        printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
        err = mtd->read(mtd, addr0, pgsize, &read, twopages);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != pgsize) {
                printk(PRINT_PREF "error: read failed at %#llx\n",
index 587e1e371c6c50c059785e3b0c354f4f1f6fd450..756045345f009e5f6d4be831c48d67358512b86d 100644 (file)
@@ -75,7 +75,7 @@ static int read_eraseblock_by_page(int ebnum)
                        ops.datbuf    = NULL;
                        ops.oobbuf    = oobbuf;
                        ret = mtd->read_oob(mtd, addr, &ops);
-                       if ((ret && ret != -EUCLEAN) ||
+                       if ((ret && !mtd_is_bitflip(ret)) ||
                                        ops.oobretlen != mtd->oobsize) {
                                printk(PRINT_PREF "error: read oob failed at "
                                                  "%#llx\n", (long long)addr);
index 627d4e2466a3bccbedd3ca27c304f2b47bd414ca..79d53ee622951d19e84dbf619ccbdb5d5929d3d8 100644 (file)
@@ -216,7 +216,7 @@ static int read_eraseblock(int ebnum)
 
        err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf);
        /* Ignore corrected ECC errors */
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (err || read != mtd->erasesize) {
                printk(PRINT_PREF "error: read failed at %#llx\n", addr);
@@ -237,7 +237,7 @@ static int read_eraseblock_by_page(int ebnum)
        for (i = 0; i < pgcnt; i++) {
                err = mtd->read(mtd, addr, pgsize, &read, buf);
                /* Ignore corrected ECC errors */
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != pgsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -263,7 +263,7 @@ static int read_eraseblock_by_2pages(int ebnum)
        for (i = 0; i < n; i++) {
                err = mtd->read(mtd, addr, sz, &read, buf);
                /* Ignore corrected ECC errors */
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != sz) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -278,7 +278,7 @@ static int read_eraseblock_by_2pages(int ebnum)
        if (pgcnt % 2) {
                err = mtd->read(mtd, addr, pgsize, &read, buf);
                /* Ignore corrected ECC errors */
-               if (err == -EUCLEAN)
+               if (mtd_is_bitflip(err))
                        err = 0;
                if (err || read != pgsize) {
                        printk(PRINT_PREF "error: read failed at %#llx\n",
index 531625fc9259cdd167f0ade4755cf1f71cdefaa2..3c9008adbe3b9478598884f2d8c54a0abd11ecac 100644 (file)
@@ -154,7 +154,7 @@ static int do_read(void)
        }
        addr = eb * mtd->erasesize + offs;
        err = mtd->read(mtd, addr, len, &read, readbuf);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                err = 0;
        if (unlikely(err || read != len)) {
                printk(PRINT_PREF "error: read failed at 0x%llx\n",
index 334eae53a3dba64a50ce117d83883434fa53cd91..2b51842d08faacc24d1cf3c9c234dfab3626af2a 100644 (file)
@@ -198,7 +198,7 @@ static int verify_eraseblock(int ebnum)
        read = 0;
        err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
        if (unlikely(err || read != subpgsize)) {
-               if (err == -EUCLEAN && read == subpgsize) {
+               if (mtd_is_bitflip(err) && read == subpgsize) {
                        printk(PRINT_PREF "ECC correction at %#llx\n",
                               (long long)addr);
                        err = 0;
@@ -226,7 +226,7 @@ static int verify_eraseblock(int ebnum)
        read = 0;
        err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
        if (unlikely(err || read != subpgsize)) {
-               if (err == -EUCLEAN && read == subpgsize) {
+               if (mtd_is_bitflip(err) && read == subpgsize) {
                        printk(PRINT_PREF "ECC correction at %#llx\n",
                               (long long)addr);
                        err = 0;
@@ -264,7 +264,7 @@ static int verify_eraseblock2(int ebnum)
                read = 0;
                err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf);
                if (unlikely(err || read != subpgsize * k)) {
-                       if (err == -EUCLEAN && read == subpgsize * k) {
+                       if (mtd_is_bitflip(err) && read == subpgsize * k) {
                                printk(PRINT_PREF "ECC correction at %#llx\n",
                                       (long long)addr);
                                err = 0;
@@ -298,7 +298,7 @@ static int verify_eraseblock_ff(int ebnum)
                read = 0;
                err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
                if (unlikely(err || read != subpgsize)) {
-                       if (err == -EUCLEAN && read == subpgsize) {
+                       if (mtd_is_bitflip(err) && read == subpgsize) {
                                printk(PRINT_PREF "ECC correction at %#llx\n",
                                       (long long)addr);
                                err = 0;
index 5c6c3d2489014960056a5f27916a8c2924810549..25786ce97c8e16c509f06272d10b10f891cba6dd 100644 (file)
@@ -138,7 +138,7 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf)
 
 retry:
        err = mtd->read(mtd, addr, len, &read, check_buf);
-       if (err == -EUCLEAN)
+       if (mtd_is_bitflip(err))
                printk(PRINT_PREF "single bit flip occurred at EB %d "
                       "MTD reported that it was fixed.\n", ebnum);
        else if (err) {
index 4be671815014ee3b054f2ba8f704781dfbc1f032..fb7f19b62d91fabe2fdc785bf08aa1a32f523497 100644 (file)
@@ -443,7 +443,7 @@ retry:
                if (err == UBI_IO_BITFLIPS) {
                        scrub = 1;
                        err = 0;
-               } else if (err == -EBADMSG) {
+               } else if (mtd_is_eccerr(err)) {
                        if (vol->vol_type == UBI_DYNAMIC_VOLUME)
                                goto out_unlock;
                        scrub = 1;
index 6ba55c2358738d3d3645f816b55c0286ee15562b..f20b6f22f240378ce6386ee8c4e59d25f81cb3de 100644 (file)
@@ -172,9 +172,9 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
 retry:
        err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
        if (err) {
-               const char *errstr = (err == -EBADMSG) ? " (ECC error)" : "";
+               const char *errstr = mtd_is_eccerr(err) ? " (ECC error)" : "";
 
-               if (err == -EUCLEAN) {
+               if (mtd_is_bitflip(err)) {
                        /*
                         * -EUCLEAN is reported if there was a bit-flip which
                         * was corrected, so this is harmless.
@@ -205,7 +205,7 @@ retry:
                 * all the requested data. But some buggy drivers might do
                 * this, so we change it to -EIO.
                 */
-               if (read != len && err == -EBADMSG) {
+               if (read != len && mtd_is_eccerr(err)) {
                        ubi_assert(0);
                        err = -EIO;
                }
@@ -469,7 +469,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
 
 out:
        mutex_unlock(&ubi->buf_mutex);
-       if (err == UBI_IO_BITFLIPS || err == -EBADMSG) {
+       if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
                /*
                 * If a bit-flip or data integrity error was detected, the test
                 * 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,
 
        read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
        if (read_err) {
-               if (read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG)
+               if (read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
                        return read_err;
 
                /*
@@ -776,7 +776,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
 
        magic = be32_to_cpu(ec_hdr->magic);
        if (magic != UBI_EC_HDR_MAGIC) {
-               if (read_err == -EBADMSG)
+               if (mtd_is_eccerr(read_err))
                        return UBI_IO_BAD_HDR_EBADMSG;
 
                /*
@@ -1032,12 +1032,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
        p = (char *)vid_hdr - ubi->vid_hdr_shift;
        read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
                          ubi->vid_hdr_alsize);
-       if (read_err && read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG)
+       if (read_err && read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
                return read_err;
 
        magic = be32_to_cpu(vid_hdr->magic);
        if (magic != UBI_VID_HDR_MAGIC) {
-               if (read_err == -EBADMSG)
+               if (mtd_is_eccerr(read_err))
                        return UBI_IO_BAD_HDR_EBADMSG;
 
                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)
                return -ENOMEM;
 
        err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
-       if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG)
+       if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
                goto exit;
 
        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)
        p = (char *)vid_hdr - ubi->vid_hdr_shift;
        err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
                          ubi->vid_hdr_alsize);
-       if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG)
+       if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
                goto exit;
 
        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,
        }
 
        err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1);
-       if (err && err != -EUCLEAN)
+       if (err && !mtd_is_bitflip(err))
                goto out_free;
 
        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)
        }
 
        err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
-       if (err && err != -EUCLEAN) {
+       if (err && !mtd_is_bitflip(err)) {
                ubi_err("error %d while reading %d bytes from PEB %d:%d, "
                        "read %zd bytes", err, len, pnum, offset, read);
                goto error;
index d39716e5b204c8fce14e2383dfdc1d43c91d972d..1a35fc5e3b40a947451acc340b58b7c29f2ded41 100644 (file)
@@ -410,7 +410,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
                return 0;
 
        err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check);
-       if (err && err == -EBADMSG && vol->vol_type == UBI_STATIC_VOLUME) {
+       if (err && mtd_is_eccerr(err) && vol->vol_type == UBI_STATIC_VOLUME) {
                ubi_warn("mark volume %d as corrupted", vol_id);
                vol->corrupted = 1;
        }
index ff2a65c37f69a6c12e7dbbdafb0c8367e951ce49..f6a7d7ac4b98a6fb1f2dd3b8d2f0abad4b06bd45 100644 (file)
@@ -81,7 +81,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
 
                err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);
                if (err) {
-                       if (err == -EBADMSG)
+                       if (mtd_is_eccerr(err))
                                err = 1;
                        break;
                }
index a3a198f9b98dd05ea7690f4239c6874a9a3f0526..0cb17d936b5a46581ab6360c1b8307211b3c01c0 100644 (file)
@@ -395,7 +395,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
        }
 
        err = ubi_io_read_data(ubi, buf, pnum, 0, len);
-       if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG)
+       if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
                goto out_free_buf;
 
        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,
 
        err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start,
                          ubi->leb_size);
-       if (err == UBI_IO_BITFLIPS || err == -EBADMSG) {
+       if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
                /*
                 * Bit-flips or integrity errors while reading the data area.
                 * It is difficult to say for sure what type of corruption is
index 4b50a3029b8467817c582eb6488007cfa3fdfd46..9ad18da1891de31d2e792de57ede91626764e431 100644 (file)
@@ -423,7 +423,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 
                err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
                                       ubi->vtbl_size);
-               if (err == UBI_IO_BITFLIPS || err == -EBADMSG)
+               if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err))
                        /*
                         * Scrub the PEB later. Note, -EBADMSG indicates an
                         * uncorrectable ECC error, but we have our own CRC and