From patchwork Fri Jun 8 15:41:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shmulik Ladkani X-Patchwork-Id: 163807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C5202B6FBB for ; Sat, 9 Jun 2012 01:43:16 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Sd1Ji-0003FW-NJ; Fri, 08 Jun 2012 15:41:38 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Sd1Jf-0003E9-Lp for linux-mtd@lists.infradead.org; Fri, 08 Jun 2012 15:41:36 +0000 Received: by lbbgg6 with SMTP id gg6so1676706lbb.36 for ; Fri, 08 Jun 2012 08:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; bh=e9KXUgUfXJzYSgsklsn9mtUcgJYAZ0t2tNTyon9jvLw=; b=wGu3rPY62qUKOq8RNLjjbRLWSOegQUmcB4pYybS+PjiQxbVMAy9Up7AtUZ2L+jyqA+ U4P5ROpimgsGEMXKIqeSEtawYD6bnjbxv8YauwsM4v4bIPGu+15xxFbfj076dw+DxJoO OknMBJxwESgUmt5BC3EsOuTGx5ek5K6qI26AwQlhsTuHGPrtCVfp9A6WkwuaZQG4/Qj3 LofRPyA/7RVnnnV7SkQ6/WrIftAXmziFbxf+9EokE1UrC+mFXuiMPeI/FQf/TdfzQv2T vHa46xsZ2yKWM/9JHjnwJhATYE9urc+l6P+MlWbH4nH/0ZwZKqXtLehe5cNmzdBaJfQe MlLg== Received: by 10.112.83.198 with SMTP id s6mr4101390lby.76.1339170093300; Fri, 08 Jun 2012 08:41:33 -0700 (PDT) Received: from halley (109-186-124-80.bb.netvision.net.il. [109.186.124.80]) by mx.google.com with ESMTPS id fv16sm10170270lab.9.2012.06.08.08.41.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jun 2012 08:41:32 -0700 (PDT) Date: Fri, 8 Jun 2012 18:41:26 +0300 From: Shmulik Ladkani To: David Woodhouse , Artem Bityutskiy Subject: [PATCH] mtd: nand: Properly initialize 'mtd->bitflip_threshold' prior 'scan_bbt()' is invoked Message-ID: <20120608184126.6dce8977@halley> X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.6; i686-pc-linux-gnu) Mime-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (shmulik.ladkani[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: linux-mtd@lists.infradead.org, Sascha Hauer , Mike Dunn , Ivan Djelic , linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org As of edbc454 [mtd: driver _read() returns max_bitflips; mtd_read() returns -EUCLEAN], 'mtd->bitflip_threshold' must be set for mtd devices having ECC, prior any 'mtd_read()' call. Otherwise, 'mtd_read()' will falsely return -EUCLEAN. Normally, 'mtd->bitflip_threshold' is initialized when the MTD is added. However, this is too late for NAND MTDs, as 'scan_bbt()' is invoked prior the existing initialization of 'mtd->bitflip_threshold'. This is a problem since 'scan_bbt()' calls 'mtd_read()', in the case of a flash-based bad block table. It resulted in a falsely reported bitflips indication during BBT read, which lead to constant scrubbing of the flash BBT blocks. Initialize 'mtd->bitflip_threshold' to its default value (if not already set by the driver), prior invocation of 'scan_bbt()'. Reported-by: Sascha Hauer Signed-off-by: Shmulik Ladkani --- - The issue was introduced in v3.5-rc1, and needs to be merged prior v3.5 - Sascha, I've credited you as reporter, is that ok with you? - Sashca, care to test the fix on your system? diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 61805e7..0a8724e 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -3484,6 +3484,13 @@ int nand_scan_tail(struct mtd_info *mtd) /* propagate ecc info to mtd_info */ mtd->ecclayout = chip->ecc.layout; mtd->ecc_strength = chip->ecc.strength; + /* + * Initialize bitflip_threshold to its default prior scan_bbt() call. + * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be + * properly set. + */ + if (!mtd->bitflip_threshold) + mtd->bitflip_threshold = mtd->ecc_strength; /* Check, if we should skip the bad block table scan */ if (chip->options & NAND_SKIP_BBTSCAN)