]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mtd: nand: Fix nand_do_read_oob() return value
authorMiquel Raynal <miquel.raynal@free-electrons.com>
Fri, 12 Jan 2018 09:13:36 +0000 (10:13 +0100)
committerSasha Levin <alexander.levin@microsoft.com>
Thu, 1 Mar 2018 03:09:51 +0000 (22:09 -0500)
[ Upstream commit 87e89ce8d0d14f573c068c61bec2117751fb5103 ]

Starting from commit 041e4575f034 ("mtd: nand: handle ECC errors in
OOB"), nand_do_read_oob() (from the NAND core) did return 0 or a
negative error, and the MTD layer expected it.

However, the trend for the NAND layer is now to return an error or a
positive number of bitflips. Deciding which status to return to the user
belongs to the MTD layer.

Commit e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()")
brought this logic to the mtd_read_oob() function while the return value
coming from nand_do_read_oob() (called by the ->_read_oob() hook) was
left unchanged.

Fixes: e47f68587b82 ("mtd: check for max_bitflips in mtd_read_oob()")
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
drivers/mtd/nand/nand_base.c

index f84113fc7cb7a7a9071e09e1e5a06dd813505ea6..14a5f559e300f4cf5ffedb2a42aa1f33606f6519 100644 (file)
@@ -1889,6 +1889,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
 static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
                            struct mtd_oob_ops *ops)
 {
+       unsigned int max_bitflips = 0;
        int page, realpage, chipnr;
        struct nand_chip *chip = mtd->priv;
        struct mtd_ecc_stats stats;
@@ -1949,6 +1950,8 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
                                nand_wait_ready(mtd);
                }
 
+               max_bitflips = max_t(unsigned int, max_bitflips, ret);
+
                readlen -= len;
                if (!readlen)
                        break;
@@ -1974,7 +1977,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
        if (mtd->ecc_stats.failed - stats.failed)
                return -EBADMSG;
 
-       return  mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
+       return max_bitflips;
 }
 
 /**