From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] mtd: fix mtd_read return value
Date: Fri, 20 Dec 2013 15:10:19 +0100 [thread overview]
Message-ID: <1387548620-26893-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1387548620-26893-1-git-send-email-s.hauer@pengutronix.de>
mtd->read returns the number of bitflips as positive numbers.
Instead of returning these numbers Return -EUCLEAN when the bitflip
threshold has been reached, 0 otherwise.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 0abe667..fc2ac00 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -313,7 +313,20 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
u_char *buf)
{
- return mtd->read(mtd, from, len, retlen, buf);
+ int ret_code;
+ *retlen = 0;
+
+ /*
+ * In the absence of an error, drivers return a non-negative integer
+ * representing the maximum number of bitflips that were corrected on
+ * any one ecc region (if applicable; zero otherwise).
+ */
+ ret_code = mtd->read(mtd, from, len, retlen, buf);
+ if (unlikely(ret_code < 0))
+ return ret_code;
+ if (mtd->ecc_strength == 0)
+ return 0; /* device lacks ecc */
+ return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
}
int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
--
1.8.5.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-12-20 14:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-20 14:10 mtd/UBI fixes Sascha Hauer
2013-12-20 14:10 ` [PATCH 1/3] mtd: fix wrong return values in cdev read Sascha Hauer
2013-12-20 14:10 ` Sascha Hauer [this message]
2013-12-20 14:10 ` [PATCH 3/3] mtd: Add subpagesize to mtd_info_user 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=1387548620-26893-3-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