diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-12-20 13:47:42 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-12-20 15:04:30 +0100 |
commit | 080a4e9c9b43d0a1cda7726bf14a828d4eff3b01 (patch) | |
tree | 3be78952927005bfae2853b296348c5285f1a6bf /drivers | |
parent | a8fd9bfd126cee8a02400f49301fb58228a2bf26 (diff) | |
download | barebox-080a4e9c9b43d0a1cda7726bf14a828d4eff3b01.tar.gz barebox-080a4e9c9b43d0a1cda7726bf14a828d4eff3b01.tar.xz |
mtd: fix mtd_read return value
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/core.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 0abe6675e7..fc2ac00336 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, |