From patchwork Thu Feb 13 00:46:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 319851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0777A2C0081 for ; Thu, 13 Feb 2014 11:47:51 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDkSf-0003FW-18; Thu, 13 Feb 2014 00:47:29 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDkSd-0006d0-Dy; Thu, 13 Feb 2014 00:47:27 +0000 Received: from mail-oa0-x22e.google.com ([2607:f8b0:4003:c02::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDkSa-0006ce-Kh for linux-mtd@lists.infradead.org; Thu, 13 Feb 2014 00:47:25 +0000 Received: by mail-oa0-f46.google.com with SMTP id n16so11848372oag.19 for ; Wed, 12 Feb 2014 16:47:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=irYywZ9wHYqMkqoltPnJMtVw0hrbhq+iKIvDtHjRUaE=; b=QRI7YsShPf4LCx2J1J0NkJ8PJrf7sISeGFzxtPjxjQgymvhAmhXG5va81tocCu4gaJ frwuknNOd6TQ22vNcJ12xBae1ZzMraD8O/ehlYNOzTh1XbSlQelUe/32NVQOem0Zz3uI ExJBd6EFE/YBAzyRcff0MuCTClKOBC4ARl8a4oZLc0mpDsNCWCmFN9MTEUZ1QGrSIuFv vTnI6uddUDuvBPuBst74cYwvAj2uzXMg/q4jo32xv+bb2WiZ+Sndfyd+Ycgd9VOCebcE XhF0cdvsAhzykxfMSZdTiwtpY7WIWXIBmG371ZIW6F4gp97ECvbuSRaxdCwxWyHDCIl4 YoqA== X-Received: by 10.60.54.138 with SMTP id j10mr4535872oep.51.1392252422796; Wed, 12 Feb 2014 16:47:02 -0800 (PST) Received: from ld-irv-0074.broadcom.com (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id g4sm350616obe.5.2014.02.12.16.47.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Feb 2014 16:47:02 -0800 (PST) From: Brian Norris To: Subject: [PATCH] mtd: nand: fix off-by-one read retry mode counting Date: Wed, 12 Feb 2014 16:46:34 -0800 Message-Id: <1392252394-32512-1-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140212_194724_782055_9283EE59 X-CRM114-Status: GOOD ( 10.66 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Huang Shijie , Brian Norris X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org A flash may support N read retry voltage threshold modes, numbered 1 through N (where mode 0 represents the initial state). However, nand_setup_read_retry() prematurely quits with an error when mode == N. This off-by-one error shows up, for instance, when using nanddump, and we have cycled through available modes: nand: setting READ RETRY mode 0 nand: setting READ RETRY mode 1 nand: setting READ RETRY mode 2 nand: setting READ RETRY mode 3 nand: setting READ RETRY mode 4 nand: setting READ RETRY mode 5 nand: setting READ RETRY mode 6 nand: setting READ RETRY mode 7 nand: setting READ RETRY mode 8 libmtd: error!: cannot read 8192 bytes from mtd0 (eraseblock 20, offset 0) error 22 (Invalid argument) nanddump: error!: mtd_read Tested on Micron MT29F64G08CBCBBH1, with 8 retry modes. Signed-off-by: Brian Norris --- drivers/mtd/nand/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 9be7842f300e..76535a61b87a 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1471,7 +1471,7 @@ static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) pr_debug("setting READ RETRY mode %d\n", retry_mode); - if (retry_mode >= chip->read_retries) + if (retry_mode > chip->read_retries) return -EINVAL; if (!chip->setup_read_retry)