From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 13/16] mtd: ubi: Use mtd_peb_read
Date: Tue, 15 Mar 2016 12:15:31 +0100 [thread overview]
Message-ID: <1458040534-6171-14-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1458040534-6171-1-git-send-email-s.hauer@pengutronix.de>
mtd_peb_read provides the same functionality as ubi_io_read. Use
it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/ubi/debug.h | 13 --------
drivers/mtd/ubi/io.c | 89 +++----------------------------------------------
2 files changed, 5 insertions(+), 97 deletions(-)
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index ebf961b..f177e6b 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -73,19 +73,6 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
}
/**
- * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
- * @ubi: UBI device description object
- *
- * Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
- */
-static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
-{
- if (ubi->dbg.emulate_bitflips)
- return !(random32() % 200);
- return 0;
-}
-
-/**
* ubi_dbg_is_write_failure - if it is time to emulate a write failure.
* @ubi: UBI device description object
*
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 4031253..4fa8e5d 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -121,91 +121,12 @@ static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum,
int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
int len)
{
- int err, retries = 0;
- size_t read;
- loff_t addr;
-
- dbg_io("read %d bytes from PEB %d:%d", len, pnum, offset);
-
- ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
- ubi_assert(offset >= 0 && offset + len <= ubi->peb_size);
- ubi_assert(len > 0);
-
- err = self_check_not_bad(ubi, pnum);
- if (err)
- return err;
-
- /*
- * Deliberately corrupt the buffer to improve robustness. Indeed, if we
- * do not do this, the following may happen:
- * 1. The buffer contains data from previous operation, e.g., read from
- * another PEB previously. The data looks like expected, e.g., if we
- * just do not read anything and return - the caller would not
- * notice this. E.g., if we are reading a VID header, the buffer may
- * contain a valid VID header from another PEB.
- * 2. The driver is buggy and returns us success or -EBADMSG or
- * -EUCLEAN, but it does not actually put any data to the buffer.
- *
- * This may confuse UBI or upper layers - they may think the buffer
- * contains valid data while in fact it is just old data. This is
- * especially possible because UBI (and UBIFS) relies on CRC, and
- * treats data as correct even in case of ECC errors if the CRC is
- * correct.
- *
- * Try to prevent this situation by changing the first byte of the
- * buffer.
- */
- *((uint8_t *)buf) ^= 0xFF;
-
- addr = (loff_t)pnum * ubi->peb_size + offset;
-retry:
- err = mtd_read(ubi->mtd, addr, len, &read, buf);
- if (err) {
- const char *errstr = mtd_is_eccerr(err) ? " (ECC error)" : "";
-
- if (mtd_is_bitflip(err)) {
- /*
- * -EUCLEAN is reported if there was a bit-flip which
- * was corrected, so this is harmless.
- *
- * We do not report about it here unless debugging is
- * enabled. A corresponding message will be printed
- * later, when it is has been scrubbed.
- */
- ubi_msg("fixable bit-flip detected at PEB %d", pnum);
- ubi_assert(len == read);
- return UBI_IO_BITFLIPS;
- }
+ int ret;
- if (retries++ < UBI_IO_RETRIES) {
- ubi_warn("error %d%s while reading %d bytes from PEB %d:%d, read only %zd bytes, retry",
- err, errstr, len, pnum, offset, read);
- goto retry;
- }
-
- ubi_err("error %d%s while reading %d bytes from PEB %d:%d, read %zd bytes",
- err, errstr, len, pnum, offset, read);
- dump_stack();
-
- /*
- * The driver should never return -EBADMSG if it failed to read
- * all the requested data. But some buggy drivers might do
- * this, so we change it to -EIO.
- */
- if (read != len && mtd_is_eccerr(err)) {
- ubi_assert(0);
- err = -EIO;
- }
- } else {
- ubi_assert(len == read);
-
- if (ubi_dbg_is_bitflip(ubi)) {
- dbg_gen("bit-flip (emulated)");
- err = UBI_IO_BITFLIPS;
- }
- }
-
- return err;
+ ret = mtd_peb_read(ubi->mtd, buf, pnum, offset, len);
+ if (mtd_is_bitflip(ret))
+ return UBI_IO_BITFLIPS;
+ return ret;
}
/**
--
2.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-03-15 11:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-15 11:15 Introduce mtd-peb API Sascha Hauer
2016-03-15 11:15 ` [PATCH 01/16] mtd: Add support for marking blocks as good Sascha Hauer
2016-03-15 11:15 ` [PATCH 02/16] mtd: nand: Add option to print bbt in nand command Sascha Hauer
2016-03-15 11:15 ` [PATCH 03/16] mtd: mtdpart: Add oob_read function Sascha Hauer
2016-03-15 11:15 ` [PATCH 04/16] mtd: Introduce function to get mtd type string Sascha Hauer
2016-03-15 11:15 ` [PATCH 05/16] mtd: rename mtd_all_ff -> mtd_buf_all_ff Sascha Hauer
2016-03-15 11:15 ` [PATCH 06/16] mtd: Introduce mtd_check_pattern Sascha Hauer
2016-03-15 11:15 ` [PATCH 07/16] mtd: Introduce mtd-peb API Sascha Hauer
2016-03-15 11:15 ` [PATCH 08/16] ubiformat: Use " Sascha Hauer
2016-03-15 11:15 ` [PATCH 09/16] remove now unused libmtd Sascha Hauer
2016-03-15 11:15 ` [PATCH 10/16] mtd: ubi: Use mtd_all_ff/mtd_check_pattern Sascha Hauer
2016-03-15 11:15 ` [PATCH 11/16] mtd: ubi: Use mtd_peb_check_all_ff Sascha Hauer
2016-03-15 11:15 ` [PATCH 12/16] mtd: ubi: Use mtd_peb_torture Sascha Hauer
2016-03-15 11:15 ` Sascha Hauer [this message]
2016-03-15 11:15 ` [PATCH 14/16] mtd: ubi: Use mtd_peb_write Sascha Hauer
2016-03-15 11:15 ` [PATCH 15/16] mtd: ubi: Use mtd_peb_erase Sascha Hauer
2016-03-15 11:15 ` [PATCH 16/16] mtd: ubi: Make debug options configurable Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458040534-6171-14-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox