From patchwork Sun May 3 07:18:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 6320491 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 695D29F374 for ; Sun, 3 May 2015 07:27:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8352220456 for ; Sun, 3 May 2015 07:27:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 054A120429 for ; Sun, 3 May 2015 07:27:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YooFH-0001X7-MV; Sun, 03 May 2015 07:23:23 +0000 Received: from guitar.tcltek.co.il ([192.115.133.116] helo=mx.tkos.co.il) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YooEb-0001KF-Gh; Sun, 03 May 2015 07:22:45 +0000 Received: from tarshish.tkos.co.il (unknown [10.0.8.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPSA id A8900440856; Sun, 3 May 2015 10:22:15 +0300 (IDT) From: Baruch Siach To: David Woodhouse , Brian Norris Subject: [PATCH v2 2/4] mtd: mxc_nand: limit the size of used oob Date: Sun, 3 May 2015 10:18:52 +0300 Message-Id: <2c8e1c7b83aa1c955e54479534867c4b754ee4dc.1430636819.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150503_002241_973134_9E7AB335 X-CRM114-Status: GOOD ( 15.58 ) X-Spam-Score: 0.0 (/) Cc: Fabio Estevam , Baruch Siach , linux-mtd@lists.infradead.org, Sascha Hauer , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For 4k pages the i.MX NFC hardware uses no more than 218 bytes for 8bit ECC data. Larger oobsize confuses the logic of copy_spare(). Limit the size of used oob size to avoid that. Signed-off-by: Baruch Siach --- v2: * Move used_oobsize into struct mxc_nand_host, and initialize it from _probe() (Uwe Kleine-König) * Add a more details to in-code comment --- drivers/mtd/nand/mxc_nand.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 33b22b9c0b30..51c1600d7eb9 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -189,6 +189,7 @@ struct mxc_nand_host { int clk_act; int irq; int eccsize; + int used_oobsize; int active_cs; struct completion op_completion; @@ -827,7 +828,7 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom) u16 sparebuf_size = host->devtype_data->spare_len; /* size of oob chunk for all but possibly the last one */ - oob_chunk_size = (mtd->oobsize / num_chunks) & ~1; + oob_chunk_size = (host->used_oobsize / num_chunks) & ~1; if (bfrom) { for (i = 0; i < num_chunks - 1; i++) @@ -838,7 +839,7 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom) /* the last chunk */ memcpy32_fromio(d + i * oob_chunk_size, s + i * sparebuf_size, - mtd->oobsize - i * oob_chunk_size); + host->used_oobsize - i * oob_chunk_size); } else { for (i = 0; i < num_chunks - 1; i++) memcpy32_toio(&s[i * sparebuf_size], @@ -848,7 +849,7 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom) /* the last chunk */ memcpy32_toio(&s[oob_chunk_size * sparebuf_size], &d[i * oob_chunk_size], - mtd->oobsize - i * oob_chunk_size); + host->used_oobsize - i * oob_chunk_size); } } @@ -1606,6 +1607,15 @@ static int mxcnd_probe(struct platform_device *pdev) else if (mtd->writesize == 4096) this->ecc.layout = host->devtype_data->ecclayout_4k; + /* + * Experimentation shows that i.MX NFC can only handle up to 218 oob + * bytes. Limit used_oobsize to 218 so as to not confuse copy_spare() + * into copying invalid data to/from the spare IO buffer, as this + * might cause ECC data corruption when doing sub-page write to a + * partially written page. + */ + host->used_oobsize = min(mtd->oobsize, 218U); + if (this->ecc.mode == NAND_ECC_HW) { if (is_imx21_nfc(host) || is_imx27_nfc(host)) this->ecc.strength = 1;