From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0135.outbound.protection.outlook.com ([104.47.40.135]:48864 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032385AbeCAPeI (ORCPT ); Thu, 1 Mar 2018 10:34:08 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Miquel Raynal , Boris Brezillon , Sasha Levin Subject: [added to the 4.1 stable tree] mtd: nand: Fix nand_do_read_oob() return value Date: Thu, 1 Mar 2018 15:26:01 +0000 Message-ID: <20180301152116.1486-325-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Miquel Raynal This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ 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 Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin --- drivers/mtd/nand/nand_base.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index f84113fc7cb7..14a5f559e300 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1889,6 +1889,7 @@ static int nand_write_oob_syndrome(struct mtd_info *m= td, static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) { + unsigned int max_bitflips =3D 0; int page, realpage, chipnr; struct nand_chip *chip =3D mtd->priv; struct mtd_ecc_stats stats; @@ -1949,6 +1950,8 @@ static int nand_do_read_oob(struct mtd_info *mtd, lof= f_t from, nand_wait_ready(mtd); } =20 + max_bitflips =3D max_t(unsigned int, max_bitflips, ret); + readlen -=3D len; if (!readlen) break; @@ -1974,7 +1977,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, lof= f_t from, if (mtd->ecc_stats.failed - stats.failed) return -EBADMSG; =20 - return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; + return max_bitflips; } =20 /** --=20 2.14.1