Now that we are able to emulate power-cuts, we should differentiate the
power-cut emulation and input/output error cases to let the MTD user
decide what it should do.
EROFS was chosen to mimic what's done in UBI when a power-cut emulation
occurs.

Signed-off-by: Boris Brezillon <[email protected]>
---
 drivers/mtd/nand/nand_base.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index a621814..223aabdb 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1951,6 +1951,9 @@ static int nand_write_oob_std(struct mtd_info *mtd, 
struct nand_chip *chip,
 
        status = chip->waitfunc(mtd, chip);
 
+       if (unlikely(status & NAND_STATUS_POWER_CUT))
+               return -EROFS;
+
        return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
 
@@ -2009,6 +2012,8 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
 
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
        status = chip->waitfunc(mtd, chip);
+       if (unlikely(status & NAND_STATUS_POWER_CUT))
+               return -EROFS;
 
        return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
@@ -2442,6 +2447,9 @@ static int nand_write_page(struct mtd_info *mtd, struct 
nand_chip *chip,
                        status = chip->errstat(mtd, chip, FL_WRITING, status,
                                               page);
 
+               if (unlikely(status & NAND_STATUS_POWER_CUT))
+                       return -EROFS;
+
                if (status & NAND_STATUS_FAIL)
                        return -EIO;
        } else {
@@ -2868,7 +2876,7 @@ static int nand_erase(struct mtd_info *mtd, struct 
erase_info *instr)
 int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
                    int allowbbt)
 {
-       int page, status, pages_per_block, ret, chipnr;
+       int page, status = 0, pages_per_block, ret, chipnr;
        struct nand_chip *chip = mtd->priv;
        loff_t len;
 
@@ -2958,7 +2966,12 @@ int nand_erase_nand(struct mtd_info *mtd, struct 
erase_info *instr,
 
 erase_exit:
 
-       ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
+       if (instr->state == MTD_ERASE_DONE)
+               ret = 0;
+       else if (unlikely(status & NAND_STATUS_POWER_CUT))
+               ret = -EROFS;
+       else
+               ret = -EIO;
 
        /* Deselect and wake up anyone waiting on the device */
        chip->select_chip(mtd, -1);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to