lkml.org 
[lkml]   [2015]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation
Date
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 <boris.brezillon@free-electrons.com>
---
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


\
 
 \ /
  Last update: 2015-09-25 17:21    [W:0.088 / U:0.772 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site