mtd: nand: check the return code of 'read_oob/read_oob_raw'

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon May 28 07:59:12 EDT 2012


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=1951f2f710a621ae0bc4268617046a6c02c634d0
Commit:     1951f2f710a621ae0bc4268617046a6c02c634d0
Parent:     5c2ffb11d40dd967eecb45b8570a871746ba124b
Author:     Shmulik Ladkani <shmulik.ladkani at gmail.com>
AuthorDate: Wed May 9 13:13:34 2012 +0300
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Sun May 13 23:25:00 2012 -0500

    mtd: nand: check the return code of 'read_oob/read_oob_raw'
    
    Apparently, there is an implementor of 'read_oob' which may return an
    error inidication (e.g. docg4_read_oob may return -EIO).
    
    Test the return value of 'read_oob/read_oob_raw', and if negative,
    propagate the error, so it's returned by the '_read_oob' interface.
    
    Signed-off-by: Shmulik Ladkani <shmulik.ladkani at gmail.com>
    Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/nand/nand_base.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 4047d7c..d47586c 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1791,6 +1791,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 	int readlen = ops->ooblen;
 	int len;
 	uint8_t *buf = ops->oobbuf;
+	int ret = 0;
 
 	pr_debug("%s: from = 0x%08Lx, len = %i\n",
 			__func__, (unsigned long long)from, readlen);
@@ -1826,9 +1827,12 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 
 	while (1) {
 		if (ops->mode == MTD_OPS_RAW)
-			chip->ecc.read_oob_raw(mtd, chip, page);
+			ret = chip->ecc.read_oob_raw(mtd, chip, page);
 		else
-			chip->ecc.read_oob(mtd, chip, page);
+			ret = chip->ecc.read_oob(mtd, chip, page);
+
+		if (ret < 0)
+			break;
 
 		len = min(len, readlen);
 		buf = nand_transfer_oob(chip, buf, ops, len);
@@ -1857,7 +1861,10 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 		}
 	}
 
-	ops->oobretlen = ops->ooblen;
+	ops->oobretlen = ops->ooblen - readlen;
+
+	if (ret < 0)
+		return ret;
 
 	if (mtd->ecc_stats.failed - stats.failed)
 		return -EBADMSG;



More information about the linux-mtd-cvs mailing list