Skip to content

Commit

Permalink
mtd: utilize `mtd_is_*()' functions
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Norris <[email protected]>
Signed-off-by: Artem Bityutskiy <[email protected]>
  • Loading branch information
computersforpeace authored and dedekind committed Sep 21, 2011
1 parent 7387ce7 commit d57f405
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 78 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/inftlcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -917,7 +917,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
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;
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions drivers/mtd/mtdconcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdoops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions drivers/mtd/mtdpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions drivers/mtd/mtdswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -678,7 +678,7 @@ static int mtdswap_write_block(struct mtdswap_dev *d, char *buf,
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;
Expand All @@ -690,7 +690,7 @@ static int mtdswap_write_block(struct mtdswap_dev *d, char *buf,

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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ static int mtdswap_readsect(struct mtd_blktrans_dev *dev,
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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/diskonchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/nand/nand_bbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/nftlcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions drivers/mtd/onenand/onenand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/sm_ftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int sm_read_sector(struct sm_ftl *ftl,
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;
Expand All @@ -306,7 +306,7 @@ static int sm_read_sector(struct sm_ftl *ftl,
}

/* 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",
Expand Down
Loading

0 comments on commit d57f405

Please sign in to comment.