Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1232883
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation |
| Date | 2015-09-25 17:20 +0200 |
| Message-ID | <qcCX0-58P-19@gated-at.bofh.it> (permalink) |
| References | <qcCWZ-58P-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 0/5] mtd: nand/UBI: add power-cut emulation Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200
[PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200
Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS Richard Weinberger <richard@nod.at> - 2015-09-25 19:40 +0200
Re: [PATCH 3/5] UBI: switch the UBI device in read-only mode when mtd returns -EROFS Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-26 10:50 +0200
[PATCH 2/5] mtd: nand: return -EROFS in case of power-cut emulation Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-09-25 17:20 +0200
csiph-web