From patchwork Mon Jan 9 12:24:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar Kushwaha X-Patchwork-Id: 135012 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 15DFFB6F71 for ; Mon, 9 Jan 2012 23:26:10 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RkEH6-0003fs-FL; Mon, 09 Jan 2012 12:24:28 +0000 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RkEH0-0003fC-5t for linux-mtd@lists.infradead.org; Mon, 09 Jan 2012 12:24:26 +0000 Received: from mail216-ch1-R.bigfish.com (10.43.68.253) by CH1EHSOBE017.bigfish.com (10.43.70.67) with Microsoft SMTP Server id 14.1.225.23; Mon, 9 Jan 2012 12:24:20 +0000 Received: from mail216-ch1 (localhost [127.0.0.1]) by mail216-ch1-R.bigfish.com (Postfix) with ESMTP id B197E6600F5; Mon, 9 Jan 2012 12:24:19 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh2a8h668h839h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail216-ch1 (localhost.localdomain [127.0.0.1]) by mail216-ch1 (MessageSwitch) id 1326111857589847_26738; Mon, 9 Jan 2012 12:24:17 +0000 (UTC) Received: from CH1EHSMHS007.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.249]) by mail216-ch1.bigfish.com (Postfix) with ESMTP id 8158E40246; Mon, 9 Jan 2012 12:24:17 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS007.bigfish.com (10.43.70.7) with Microsoft SMTP Server (TLS) id 14.1.225.23; Mon, 9 Jan 2012 12:24:18 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server id 14.1.355.3; Mon, 9 Jan 2012 06:24:17 -0600 Received: from b32579-VirtualBox.ap.freescale.net (b32579-VirtualBox-010232132074.ap.freescale.net [10.232.132.74] (may be forged)) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id q09CODZc024249; Mon, 9 Jan 2012 06:24:14 -0600 (CST) From: Prabhakar Kushwaha To: , Subject: [PATCH 1/2][v2] mtd/nand:Fix wrong address read in is_blank() Date: Mon, 9 Jan 2012 17:54:07 +0530 Message-ID: <1326111847-13085-1-git-send-email-prabhakar@freescale.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.182 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 SUBJ_OBFU_PUNCT_FEW Possible punctuation-obfuscated Subject: header Cc: scottwood@freescale.com, Poonam Aggrwal , Prabhakar Kushwaha 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 IFC NAND Machine calculates ECC on 512byte sector. Same is taken care in fsl_ifc_run_command() while ECC status verification. Here buffer number is calculated assuming 512byte sector and same is passed to is_blank. However in is_blank() buffer address is calculated using mdt->writesize which is wrong. It should be calculated on basis of ecc sector size. Also, in fsl_ifc_run_command() bufferpage is calculated on the basis of ecc sector size instead of hard coded value. Signed-off-by: Poonam Aggrwal Signed-off-by: Prabhakar Kushwaha --- git://git.kernel.org/pub/scm/linux/kernel/git/galak/powerpc.git (branch next) This patch is created on top of IFC driver patch (already floated in mailing list). Please find their link: http://patchwork.ozlabs.org/patch/133315/ http://patchwork.ozlabs.org/patch/133316/ Tested on P1010RDB Changes for v2: Incorporated Scott's comments - Updated copyright - is_blank - works on ecc buffer block - check_read_ecc() - Calculate actual ecc buffer number drivers/mtd/nand/fsl_ifc_nand.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c index 8475b88..c0529ea 100644 --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c @@ -1,7 +1,7 @@ /* * Freescale Integrated Flash Controller NAND driver * - * Copyright 2011 Freescale Semiconductor, Inc + * Copyright 2011,2012 Freescale Semiconductor, Inc * * Author: Dipen Dudhat * @@ -191,12 +191,12 @@ static int is_blank(struct mtd_info *mtd, unsigned int bufnum) { struct nand_chip *chip = mtd->priv; struct fsl_ifc_mtd *priv = chip->priv; - u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2); + u8 __iomem *addr = priv->vbase + bufnum * chip->ecc.size; u32 __iomem *mainarea = (u32 *)addr; u8 __iomem *oob = addr + mtd->writesize; int i; - for (i = 0; i < mtd->writesize / 4; i++) { + for (i = 0; i < chip->ecc.size / 4; i++) { if (__raw_readl(&mainarea[i]) != 0xffffffff) return 0; } @@ -215,12 +215,15 @@ static int is_blank(struct mtd_info *mtd, unsigned int bufnum) static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, u32 *eccstat, unsigned int bufnum) { + struct nand_chip *chip = mtd->priv; + int bufperpage = mtd->writesize / chip->ecc.size; + int eccbuf_num = bufnum + (bufnum / bufperpage) * bufperpage; u32 reg = eccstat[bufnum / 4]; int errors = (reg >> ((3 - bufnum % 4) * 8)) & 15; if (errors == 15) { /* uncorrectable */ /* Blank pages fail hw ECC checks */ - if (is_blank(mtd, bufnum)) + if (is_blank(mtd, eccbuf_num)) return 1; /* @@ -273,7 +276,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd) dev_err(priv->dev, "NAND Flash Write Protect Error\n"); if (nctrl->eccread) { - int bufperpage = mtd->writesize / 512; + int bufperpage = mtd->writesize / chip->ecc.size; int bufnum = (nctrl->page & priv->bufnum_mask) * bufperpage; int bufnum_end = bufnum + bufperpage - 1;